From ec42be7a2f45492697d9ec8ddc36d046546b65d4 Mon Sep 17 00:00:00 2001 From: g1879 Date: Fri, 24 Mar 2023 17:52:34 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BE=AE=E8=B0=83cookies=E5=90=8C=E6=AD=A5?= =?UTF-8?q?=E5=8A=9F=E8=83=BD=EF=BC=8C=E5=BE=85=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DrissionPage/chromium_tab.py | 8 ++++---- DrissionPage/commons/web.py | 3 ++- DrissionPage/web_page.py | 8 ++++---- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/DrissionPage/chromium_tab.py b/DrissionPage/chromium_tab.py index 81e73a6..5912094 100644 --- a/DrissionPage/chromium_tab.py +++ b/DrissionPage/chromium_tab.py @@ -287,18 +287,18 @@ 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}) - set_session_cookies(self.session, self._get_driver_cookies(as_dict=True)) + # set_session_cookies(self.session, self._get_driver_cookies(as_dict=True)) # set_session_cookies(self.session, self._get_driver_cookies(all_domains=True)) - # set_session_cookies(self.session, self._get_driver_cookies()) + set_session_cookies(self.session, self._get_driver_cookies()) def cookies_to_browser(self): """把session对象的cookies复制到浏览器""" if not self._has_driver: return - set_browser_cookies(self, super().get_cookies(as_dict=True)) + # set_browser_cookies(self, super().get_cookies(as_dict=True)) # set_browser_cookies(self, super().get_cookies(all_domains=True)) - # set_browser_cookies(self, super().get_cookies()) + set_browser_cookies(self, super().get_cookies()) def get_cookies(self, as_dict=False, all_domains=False, all_info=False): """返回cookies diff --git a/DrissionPage/commons/web.py b/DrissionPage/commons/web.py index 75e35b0..b455e72 100644 --- a/DrissionPage/commons/web.py +++ b/DrissionPage/commons/web.py @@ -259,7 +259,8 @@ def set_browser_cookies(page, cookies): if cookie.get('domain', None): try: page.run_cdp_loaded('Network.setCookie', **cookie) - continue + if is_cookie_in_driver(page, cookie): + continue except Exception: pass diff --git a/DrissionPage/web_page.py b/DrissionPage/web_page.py index 02dda53..28bc3f5 100644 --- a/DrissionPage/web_page.py +++ b/DrissionPage/web_page.py @@ -363,18 +363,18 @@ 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}) - set_session_cookies(self.session, self._get_driver_cookies(as_dict=True)) + # set_session_cookies(self.session, self._get_driver_cookies(as_dict=True)) # set_session_cookies(self.session, self._get_driver_cookies(all_domains=True)) - # set_session_cookies(self.session, self._get_driver_cookies()) + set_session_cookies(self.session, self._get_driver_cookies()) def cookies_to_browser(self): """把session对象的cookies复制到浏览器""" if not self._has_driver: return - set_browser_cookies(self, super().get_cookies(as_dict=True)) + # set_browser_cookies(self, super().get_cookies(as_dict=True)) # set_browser_cookies(self, super().get_cookies(all_domains=True)) - # set_browser_cookies(self, super().get_cookies()) + set_browser_cookies(self, super().get_cookies()) def get_cookies(self, as_dict=False, all_domains=False, all_info=False): """返回cookies