diff --git a/DrissionPage/chromium_base.py b/DrissionPage/chromium_base.py index 55e3fba..9b0cb3c 100644 --- a/DrissionPage/chromium_base.py +++ b/DrissionPage/chromium_base.py @@ -922,13 +922,14 @@ class ChromiumBaseSetter(object): cookies = cookies_to_tuple(cookies) result_cookies = [] for cookie in cookies: - if not cookie.get('domain', None): + if cookie.get('domain', None) is None: netloc = urlparse(self._page.url).netloc if netloc.replace('.', '').isdigit(): # ip cookie['domain'] = netloc else: # 域名 u = netloc.split('.') cookie['domain'] = f'.{u[-2]}.{u[-1]}' if len(u) > 1 else netloc + result_cookies.append({'value': '' if cookie['value'] is None else cookie['value'], 'name': cookie['name'], 'domain': cookie['domain']}) diff --git a/DrissionPage/chromium_frame.py b/DrissionPage/chromium_frame.py index 33e7a55..e1bb1f3 100644 --- a/DrissionPage/chromium_frame.py +++ b/DrissionPage/chromium_frame.py @@ -129,9 +129,21 @@ class ChromiumFrame(ChromiumBase): self._is_loading = False self._is_reading = False + def _onFrameNavigated(self, **kwargs): + """页面跳转时触发""" + if kwargs['frame']['frameId'] == self.frame_id and self._first_run is False and self._is_loading: + self._is_loading = True + + if self._debug: + print('navigated') + if self._debug_recorder: + self._debug_recorder.add_data((perf_counter(), '加载流程', 'navigated')) + def _onLoadEventFired(self, **kwargs): """在页面刷新、变化后重新读取页面内容""" # 用于覆盖父类方法,不能删 + self._get_new_document() + if self._debug: print('loadEventFired') if self._debug_recorder: diff --git a/DrissionPage/chromium_tab.py b/DrissionPage/chromium_tab.py index 885a2d6..e566f0c 100644 --- a/DrissionPage/chromium_tab.py +++ b/DrissionPage/chromium_tab.py @@ -108,10 +108,8 @@ class WebPageTab(SessionPage, ChromiumTab): @property def cookies(self): - if self._mode == 's': - return super().get_cookies() - elif self._mode == 'd': - return super(SessionPage, self).get_cookies() + """以dict方式返回cookies""" + return super().cookies @property def session(self): @@ -282,7 +280,7 @@ class WebPageTab(SessionPage, ChromiumTab): selenium_user_agent = self.run_cdp('Runtime.evaluate', expression='navigator.userAgent;')['result']['value'] self.session.headers.update({"User-Agent": selenium_user_agent}) - self.set.cookies(self._get_driver_cookies(as_dict=False, all_info=False), set_session=True) + self.set.cookies(self._get_driver_cookies(as_dict=True, all_info=False), set_session=True) def cookies_to_browser(self): """把session对象的cookies复制到浏览器""" @@ -294,7 +292,7 @@ class WebPageTab(SessionPage, ChromiumTab): domain = f'.{u[-2]}.{u[-1]}' if len(u) > 1 else netloc cookies = [] for cookie in super().get_cookies(): - if not cookie.get('domain', None): + if cookie.get('domain', None) is None: cookie['domain'] = domain if domain in cookie['domain']: diff --git a/DrissionPage/chromium_tab.pyi b/DrissionPage/chromium_tab.pyi index 8850afc..396d0ff 100644 --- a/DrissionPage/chromium_tab.pyi +++ b/DrissionPage/chromium_tab.pyi @@ -57,7 +57,7 @@ class WebPageTab(SessionPage, ChromiumTab): def mode(self) -> str: ... @property - def cookies(self) -> Union[dict, list]: ... + def cookies(self) -> dict: ... @property def session(self) -> Session: ... diff --git a/DrissionPage/mixpage/drission.py b/DrissionPage/mixpage/drission.py index 813caa0..40a4509 100644 --- a/DrissionPage/mixpage/drission.py +++ b/DrissionPage/mixpage/drission.py @@ -266,7 +266,7 @@ class Drission(object): except AttributeError: browser_domain = '' - if not cookie.get('domain', None): + if cookie.get('domain', None) is None: if browser_domain: if browser_domain.replace('.', '').isdigit(): # ip cookie_domain = browser_domain diff --git a/DrissionPage/web_page.py b/DrissionPage/web_page.py index 70d285d..9a68387 100644 --- a/DrissionPage/web_page.py +++ b/DrissionPage/web_page.py @@ -177,10 +177,8 @@ class WebPage(SessionPage, ChromiumPage, BasePage): @property def cookies(self): - if self._mode == 's': - return super().get_cookies() - elif self._mode == 'd': - return super(SessionPage, self).get_cookies() + """以dict方式返回cookies""" + return super().cookies @property def session(self): @@ -356,7 +354,7 @@ class WebPage(SessionPage, ChromiumPage, BasePage): selenium_user_agent = self.run_cdp('Runtime.evaluate', expression='navigator.userAgent;')['result']['value'] self.session.headers.update({"User-Agent": selenium_user_agent}) - self.set.cookies(self._get_driver_cookies(as_dict=False, all_info=False), set_session=True) + self.set.cookies(self._get_driver_cookies(as_dict=True), set_session=True) def cookies_to_browser(self): """把session对象的cookies复制到浏览器""" @@ -368,7 +366,7 @@ class WebPage(SessionPage, ChromiumPage, BasePage): domain = f'.{u[-2]}.{u[-1]}' if len(u) > 1 else netloc cookies = [] for cookie in super().get_cookies(): - if not cookie.get('domain', None): + if cookie.get('domain', None) is None: cookie['domain'] = domain if domain in cookie['domain']: @@ -460,7 +458,7 @@ class WebPage(SessionPage, ChromiumPage, BasePage): self._has_driver = None # ---------------准备废弃--------------- - def set_cookies(self, cookies, set_session=False, set_driver=False): + def set_cookies(self, cookies, set_session=True, set_driver=True): """添加cookies信息到浏览器或session对象 :param cookies: 可以接收`CookieJar`、`list`、`tuple`、`str`、`dict`格式的`cookies` :param set_session: 是否设置到Session对象 diff --git a/DrissionPage/web_page.pyi b/DrissionPage/web_page.pyi index d2086ef..042cff8 100644 --- a/DrissionPage/web_page.pyi +++ b/DrissionPage/web_page.pyi @@ -62,7 +62,7 @@ class WebPage(SessionPage, ChromiumPage, BasePage): def mode(self) -> str: ... @property - def cookies(self) -> Union[dict, list]: ... + def cookies(self) -> dict: ... @property def session(self) -> Session: ... diff --git a/setup.py b/setup.py index 84bb355..dd1f9c1 100644 --- a/setup.py +++ b/setup.py @@ -6,7 +6,7 @@ with open("README.md", "r", encoding='utf-8') as fh: setup( name="DrissionPage", - version="3.2.13", + version="3.2.14", author="g1879", author_email="g1879@qq.com", description="Python based web automation tool. It can control the browser and send and receive data packets.",