修复'__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 pass
def prev(self, index=1): def prev(self, index=1):
return None # ShadowRootElement直接继承 return None # ChromiumShadowRoot直接继承
def prevs(self) -> None: def prevs(self) -> None:
return None # ShadowRootElement直接继承 return None # ChromiumShadowRoot直接继承
def next(self, index=1): def next(self, index=1):
pass pass

View File

@ -255,14 +255,21 @@ def set_browser_cookies(page, cookies):
cookie['expires'] = int(cookie['expires']) cookie['expires'] = int(cookie['expires'])
if cookie['value'] is None: if cookie['value'] is None:
cookie['value'] = '' cookie['value'] = ''
if cookie['name'].startswith('__Secure-'):
cookie['secure'] = True
if cookie.get('domain', None): if cookie['name'].startswith('__Host-'):
try: cookie['path'] = '/'
page.run_cdp_loaded('Network.setCookie', **cookie) cookie['secure'] = True
if is_cookie_in_driver(page, cookie):
continue else:
except Exception: if cookie.get('domain', None):
pass 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) ex_url = extract(page._browser_url)
d_list = ex_url.subdomain.split('.') d_list = ex_url.subdomain.split('.')