完善浏览器cookies设置

This commit is contained in:
g1879 2023-03-24 23:21:13 +08:00
parent 1c5c38b651
commit 91624d3458
2 changed files with 10 additions and 9 deletions

View File

@ -158,8 +158,9 @@ def test_connect(ip, port):
sleep(.2) sleep(.2)
if ip in ('127.0.0.1', 'localhost'): if ip in ('127.0.0.1', 'localhost'):
raise BrowserConnectError(f'\n连接浏览器失败,可能原因:\n1、{port}端口不是Chromium内核浏览器\n' raise BrowserConnectError(f'\n连接浏览器失败,可能原因:\n1、浏览器未启动\n2、{port}端口不是Chromium内核浏览器\n'
f'2、该浏览器未允许控制\n3、和已打开的浏览器冲突请关闭') f'3、该浏览器未允许控制\n4、和已打开的浏览器冲突\n'
f'请尝试用ChromiumOptions指定别的端口和指定浏览器路径')
raise BrowserConnectError(f'{ip}:{port}浏览器无法链接。') raise BrowserConnectError(f'{ip}:{port}浏览器无法链接。')

View File

@ -268,14 +268,14 @@ def set_browser_cookies(page, cookies):
d_list = ex_url.subdomain.split('.') d_list = ex_url.subdomain.split('.')
d_list.append(f'{ex_url.domain}.{ex_url.suffix}' if ex_url.suffix else ex_url.domain) d_list.append(f'{ex_url.domain}.{ex_url.suffix}' if ex_url.suffix else ex_url.domain)
for i in range(len(d_list)): tmp = [d_list[0]]
d = f'.{".".join(d_list[i:])}' if len(d_list) > 1:
cookie['domain'] = d for i in d_list[1:]:
page.run_cdp_loaded('Network.setCookie', **cookie) tmp.append('.')
if is_cookie_in_driver(page, cookie): tmp.append(i)
break
d = f'{".".join(d_list[i:])}' for i in range(len(tmp)):
d = ''.join(tmp[i:])
cookie['domain'] = d cookie['domain'] = d
page.run_cdp_loaded('Network.setCookie', **cookie) page.run_cdp_loaded('Network.setCookie', **cookie)
if is_cookie_in_driver(page, cookie): if is_cookie_in_driver(page, cookie):