This commit is contained in:
g1879 2023-11-29 14:42:42 +08:00
parent af6a759b4a
commit 072aad6eaf
2 changed files with 10 additions and 7 deletions

View File

@ -209,10 +209,10 @@ def test_connect(ip, port, timeout=30):
sleep(.2)
raise BrowserConnectError(f'\n{ip}:{port}浏览器无法链接。\n请确认:\n1、该端口为浏览器\n'
f'2、已添加--remote-debugging-port={port}启动项\n'
f'2、已添加\'--remote-debugging-port={port}\'启动项\n'
f'3、用户文件夹没有和已打开的浏览器冲突\n'
f'4、如为无界面系统请添加--headless=new参数\n'
f'5、如果是Linux系统可能还要添加--no-sandbox启动参数\n'
f'4、如为无界面系统请添加\'--headless=new\'参数\n'
f'5、如果是Linux系统可能还要添加\'--no-sandbox\'启动参数\n'
f'可使用ChromiumOptions设置端口和用户文件夹路径。')

View File

@ -62,10 +62,13 @@ class ChromiumPage(ChromiumBase):
def _run_browser(self):
"""连接浏览器"""
is_exist = connect_browser(self._chromium_options)
ws = get(f'http://{self._chromium_options.debugger_address}/json/version',
headers={'Connection': 'close'})
if not ws:
raise BrowserConnectError('\n浏览器连接失败请检查是否启用全局代理。如有须开放127.0.0.1地址。')
try:
ws = get(f'http://{self._chromium_options.debugger_address}/json/version', headers={'Connection': 'close'})
if not ws:
raise BrowserConnectError('\n浏览器连接失败请检查是否启用全局代理。如是须设置不代理127.0.0.1地址。')
except :
raise BrowserConnectError('\n浏览器连接失败请检查是否启用全局代理。如是须设置不代理127.0.0.1地址。')
ws = ws.json()['webSocketDebuggerUrl'].split('/')[-1]
self._browser = Browser(self._chromium_options.debugger_address, ws, self)