WebPage增加quit();修复MixPage的download属性

This commit is contained in:
g1879 2022-11-28 17:34:50 +08:00
parent 94b6c2f339
commit 1d4b6290ac
4 changed files with 33 additions and 3 deletions

View File

@ -335,6 +335,13 @@ class ChromiumBase(BasePage):
result_cookies.append(c) result_cookies.append(c)
self._wait_driver.Network.setCookies(cookies=result_cookies) self._wait_driver.Network.setCookies(cookies=result_cookies)
# def set_headers(self, headers: dict) -> None:
# """设置固定发送的headers \n
# :param headers: dict格式的headers数据
# :return: None
# """
# self.run_cdp('Network.setExtraHTTPHeaders', headers=headers)
def ele(self, def ele(self,
loc_or_ele: Union[Tuple[str, str], str, ChromiumElement, 'ChromiumFrame'], loc_or_ele: Union[Tuple[str, str], str, ChromiumElement, 'ChromiumFrame'],
timeout: float = None) -> Union[ChromiumElement, 'ChromiumFrame', None]: timeout: float = None) -> Union[ChromiumElement, 'ChromiumFrame', None]:

View File

@ -53,7 +53,6 @@ class MixPage(SessionPage, DriverPage, BasePage):
self._wait_object = None self._wait_object = None
self._response = None self._response = None
self._scroll = None self._scroll = None
self._download_kit = None
if self._mode == 'd': if self._mode == 'd':
try: try:

View File

@ -317,6 +317,16 @@ class WebPage(SessionPage, ChromiumPage, BasePage):
if set_session: if set_session:
super().set_cookies(cookies) super().set_cookies(cookies)
# def set_headers(self, headers: dict) -> None:
# """设置固定发送的headers \n
# :param headers: dict格式的headers数据
# :return: None
# """
# if self._mode == 's':
# self.session.headers = headers
# elif self._mode == 'd':
# super(SessionPage, self).set_headers(headers)
def check_page(self, by_requests: bool = False) -> Union[bool, None]: def check_page(self, by_requests: bool = False) -> Union[bool, None]:
"""d模式时检查网页是否符合预期 \n """d模式时检查网页是否符合预期 \n
默认由response状态检查可重载实现针对性检查 \n 默认由response状态检查可重载实现针对性检查 \n
@ -346,6 +356,7 @@ class WebPage(SessionPage, ChromiumPage, BasePage):
"""关闭session""" """关闭session"""
if self._has_session: if self._has_session:
self.change_mode('d') self.change_mode('d')
self._session.close()
self._session = None self._session = None
self._response = None self._response = None
self._has_session = None self._has_session = None
@ -378,7 +389,7 @@ class WebPage(SessionPage, ChromiumPage, BasePage):
def _ele(self, def _ele(self,
loc_or_ele: Union[Tuple[str, str], str, ChromiumElement, SessionElement], loc_or_ele: Union[Tuple[str, str], str, ChromiumElement, SessionElement],
timeout: float = None, single: bool = True, relative:bool=False) \ timeout: float = None, single: bool = True, relative: bool = False) \
-> Union[ChromiumElement, SessionElement, ChromiumFrame, str, None, List[Union[SessionElement, str]], List[ -> Union[ChromiumElement, SessionElement, ChromiumFrame, str, None, List[Union[SessionElement, str]], List[
Union[ChromiumElement, str, ChromiumFrame]]]: Union[ChromiumElement, str, ChromiumFrame]]]:
"""返回页面中符合条件的元素、属性或节点文本,默认返回第一个 \n """返回页面中符合条件的元素、属性或节点文本,默认返回第一个 \n
@ -430,3 +441,16 @@ class WebPage(SessionPage, ChromiumPage, BasePage):
else: else:
raise TypeError('session_or_options参数只能接收Session, dict, SessionOptions或False。') raise TypeError('session_or_options参数只能接收Session, dict, SessionOptions或False。')
def quit(self) -> None:
"""关闭浏览器关闭session"""
if self._has_session:
self._session.close()
self._session = None
self._response = None
self._has_session = None
if self._has_driver:
self._tab_obj.Browser.close()
self._tab_obj.stop()
self._tab_obj = None
self._has_driver = None

View File

@ -6,7 +6,7 @@ with open("README.md", "r", encoding='utf-8') as fh:
setup( setup(
name="DrissionPage", name="DrissionPage",
version="3.0.15", version="3.0.16",
author="g1879", author="g1879",
author_email="g1879@qq.com", author_email="g1879@qq.com",
description="A module that integrates selenium and requests session, encapsulates common page operations.", description="A module that integrates selenium and requests session, encapsulates common page operations.",