From 518b2613651e88c5c90680edfcc43368f39333ce Mon Sep 17 00:00:00 2001 From: g1879 Date: Sun, 12 Mar 2023 00:13:54 +0800 Subject: [PATCH] =?UTF-8?q?3.2.16=E4=BC=98=E5=8C=96cookies=E5=A4=84?= =?UTF-8?q?=E7=90=86=E9=80=BB=E8=BE=91=EF=BC=8C=E6=81=A2=E5=A4=8D=E5=AF=B9?= =?UTF-8?q?tldextract=E4=BE=9D=E8=B5=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DrissionPage/chromium_tab.py | 6 +++++- DrissionPage/commons/web.py | 2 +- DrissionPage/web_page.py | 8 ++++++-- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/DrissionPage/chromium_tab.py b/DrissionPage/chromium_tab.py index 55ed6c8..81e73a6 100644 --- a/DrissionPage/chromium_tab.py +++ b/DrissionPage/chromium_tab.py @@ -288,13 +288,17 @@ class WebPageTab(SessionPage, ChromiumTab): 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(all_domains=True)) + # 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()) # todo: cookies的选择 + 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()) 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 aa092b6..0fcc61b 100644 --- a/DrissionPage/commons/web.py +++ b/DrissionPage/commons/web.py @@ -263,5 +263,5 @@ def set_browser_cookies(page, cookies): try: page.run_cdp_loaded('Network.setCookie', **cookie) - except Exception as e: + except Exception: pass diff --git a/DrissionPage/web_page.py b/DrissionPage/web_page.py index f667bba..3c7aa2f 100644 --- a/DrissionPage/web_page.py +++ b/DrissionPage/web_page.py @@ -362,14 +362,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=False)) # 带域名list + 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()) def cookies_to_browser(self): """把session对象的cookies复制到浏览器""" if not self._has_driver: return - set_browser_cookies(self, super().get_cookies(all_domains=True)) # todo: cookies的选择 + 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()) def get_cookies(self, as_dict=False, all_domains=False, all_info=False): """返回cookies