修复'__Secure-aa'和'__Host-'开头的cookie不能社子和问题

This commit is contained in:
g1879 2023-06-27 10:12:11 +08:00
parent 1aaaee9bf7
commit 3ca0583626
2 changed files with 16 additions and 9 deletions

View File

@ -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

View File

@ -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('.')