diff --git a/DrissionPage/commons/browser.py b/DrissionPage/commons/browser.py index 77c4c86..2943609 100644 --- a/DrissionPage/commons/browser.py +++ b/DrissionPage/commons/browser.py @@ -158,8 +158,9 @@ def test_connect(ip, port): sleep(.2) if ip in ('127.0.0.1', 'localhost'): - raise BrowserConnectError(f'\n连接浏览器失败,可能原因:\n1、{port}端口不是Chromium内核浏览器\n' - f'2、该浏览器未允许控制\n3、和已打开的浏览器冲突,请关闭') + raise BrowserConnectError(f'\n连接浏览器失败,可能原因:\n1、浏览器未启动\n2、{port}端口不是Chromium内核浏览器\n' + f'3、该浏览器未允许控制\n4、和已打开的浏览器冲突\n' + f'请尝试用ChromiumOptions指定别的端口和指定浏览器路径') raise BrowserConnectError(f'{ip}:{port}浏览器无法链接。') diff --git a/DrissionPage/commons/web.py b/DrissionPage/commons/web.py index f18fee9..e416781 100644 --- a/DrissionPage/commons/web.py +++ b/DrissionPage/commons/web.py @@ -268,14 +268,14 @@ def set_browser_cookies(page, cookies): d_list = ex_url.subdomain.split('.') 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)): - d = f'.{".".join(d_list[i:])}' - cookie['domain'] = d - page.run_cdp_loaded('Network.setCookie', **cookie) - if is_cookie_in_driver(page, cookie): - break + tmp = [d_list[0]] + if len(d_list) > 1: + for i in d_list[1:]: + tmp.append('.') + tmp.append(i) - d = f'{".".join(d_list[i:])}' + for i in range(len(tmp)): + d = ''.join(tmp[i:]) cookie['domain'] = d page.run_cdp_loaded('Network.setCookie', **cookie) if is_cookie_in_driver(page, cookie):