From 3ca058362699a37d15de9ec2039184d87a1ea7fa Mon Sep 17 00:00:00 2001 From: g1879 Date: Tue, 27 Jun 2023 10:12:11 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D'=5F=5FSecure-aa'=E5=92=8C'?= =?UTF-8?q?=5F=5FHost-'=E5=BC=80=E5=A4=B4=E7=9A=84cookie=E4=B8=8D=E8=83=BD?= =?UTF-8?q?=E7=A4=BE=E5=AD=90=E5=92=8C=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DrissionPage/base.py | 4 ++-- DrissionPage/commons/web.py | 21 ++++++++++++++------- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/DrissionPage/base.py b/DrissionPage/base.py index 052edc7..cd3ae8d 100644 --- a/DrissionPage/base.py +++ b/DrissionPage/base.py @@ -62,10 +62,10 @@ class BaseElement(BaseParser): pass def prev(self, index=1): - return None # ShadowRootElement直接继承 + return None # ChromiumShadowRoot直接继承 def prevs(self) -> None: - return None # ShadowRootElement直接继承 + return None # ChromiumShadowRoot直接继承 def next(self, index=1): pass diff --git a/DrissionPage/commons/web.py b/DrissionPage/commons/web.py index 6d14b91..2e54997 100644 --- a/DrissionPage/commons/web.py +++ b/DrissionPage/commons/web.py @@ -255,14 +255,21 @@ def set_browser_cookies(page, cookies): cookie['expires'] = int(cookie['expires']) if cookie['value'] is None: cookie['value'] = '' + if cookie['name'].startswith('__Secure-'): + cookie['secure'] = True - if cookie.get('domain', None): - try: - page.run_cdp_loaded('Network.setCookie', **cookie) - if is_cookie_in_driver(page, cookie): - continue - except Exception: - pass + if cookie['name'].startswith('__Host-'): + cookie['path'] = '/' + cookie['secure'] = True + + else: + if cookie.get('domain', None): + try: + page.run_cdp_loaded('Network.setCookie', **cookie) + if is_cookie_in_driver(page, cookie): + continue + except Exception: + pass ex_url = extract(page._browser_url) d_list = ex_url.subdomain.split('.')