mirror of
https://gitee.com/g1879/DrissionPage.git
synced 2024-12-10 04:00:23 +08:00
4.0.0b12解决连接浏览器403问题
This commit is contained in:
parent
e3f654ce12
commit
6d0f8a27f4
@ -9,8 +9,8 @@ from threading import Thread, Event
|
|||||||
from time import perf_counter
|
from time import perf_counter
|
||||||
|
|
||||||
from requests import get
|
from requests import get
|
||||||
from websocket import WebSocketTimeoutException, WebSocketException, WebSocketConnectionClosedException, \
|
from websocket import (WebSocketTimeoutException, WebSocketException, WebSocketConnectionClosedException, \
|
||||||
create_connection
|
create_connection)
|
||||||
|
|
||||||
|
|
||||||
class ChromiumDriver(object):
|
class ChromiumDriver(object):
|
||||||
@ -172,7 +172,8 @@ class ChromiumDriver(object):
|
|||||||
def start(self):
|
def start(self):
|
||||||
"""启动连接"""
|
"""启动连接"""
|
||||||
self._stopped.clear()
|
self._stopped.clear()
|
||||||
self._ws = create_connection(self._websocket_url, enable_multithread=True)
|
self._ws = create_connection(self._websocket_url, enable_multithread=True,
|
||||||
|
suppress_origin=True)
|
||||||
self._recv_th.start()
|
self._recv_th.start()
|
||||||
self._handle_event_th.start()
|
self._handle_event_th.start()
|
||||||
return True
|
return True
|
||||||
|
@ -65,7 +65,6 @@ def get_launch_args(opt):
|
|||||||
# ----------处理arguments-----------
|
# ----------处理arguments-----------
|
||||||
result = set()
|
result = set()
|
||||||
has_user_path = False
|
has_user_path = False
|
||||||
remote_allow = False
|
|
||||||
headless = None
|
headless = None
|
||||||
for i in opt.arguments:
|
for i in opt.arguments:
|
||||||
if i.startswith(('--load-extension=', '--remote-debugging-port=')):
|
if i.startswith(('--load-extension=', '--remote-debugging-port=')):
|
||||||
@ -74,8 +73,6 @@ def get_launch_args(opt):
|
|||||||
result.add(f'--user-data-dir={Path(i[16:]).absolute()}')
|
result.add(f'--user-data-dir={Path(i[16:]).absolute()}')
|
||||||
has_user_path = True
|
has_user_path = True
|
||||||
continue
|
continue
|
||||||
elif i.startswith('--remote-allow-origins='):
|
|
||||||
remote_allow = True
|
|
||||||
elif i.startswith('--headless'):
|
elif i.startswith('--headless'):
|
||||||
if i == '--headless=false':
|
if i == '--headless=false':
|
||||||
headless = False
|
headless = False
|
||||||
@ -95,9 +92,6 @@ def get_launch_args(opt):
|
|||||||
opt.set_user_data_path(path)
|
opt.set_user_data_path(path)
|
||||||
result.add(f'--user-data-dir={path}')
|
result.add(f'--user-data-dir={path}')
|
||||||
|
|
||||||
if not remote_allow:
|
|
||||||
result.add('--remote-allow-origins=*')
|
|
||||||
|
|
||||||
if headless is None and system().lower() == 'linux':
|
if headless is None and system().lower() == 'linux':
|
||||||
from os import popen
|
from os import popen
|
||||||
r = popen('systemctl list-units | grep graphical.target')
|
r = popen('systemctl list-units | grep graphical.target')
|
||||||
@ -215,7 +209,7 @@ def test_connect(ip, port, timeout=30):
|
|||||||
sleep(.2)
|
sleep(.2)
|
||||||
|
|
||||||
raise BrowserConnectError(f'\n{ip}:{port}浏览器无法链接。\n请确认:\n1、该端口为浏览器\n'
|
raise BrowserConnectError(f'\n{ip}:{port}浏览器无法链接。\n请确认:\n1、该端口为浏览器\n'
|
||||||
f'2、已添加--remote-allow-origins=*和--remote-debugging-port={port}启动项\n'
|
f'2、已添加--remote-debugging-port={port}启动项\n'
|
||||||
f'3、用户文件夹没有和已打开的浏览器冲突\n'
|
f'3、用户文件夹没有和已打开的浏览器冲突\n'
|
||||||
f'4、如为无界面系统,请添加--headless=new参数\n'
|
f'4、如为无界面系统,请添加--headless=new参数\n'
|
||||||
f'5、如果是Linux系统,可能还要添加--no-sandbox启动参数\n'
|
f'5、如果是Linux系统,可能还要添加--no-sandbox启动参数\n'
|
||||||
|
@ -4,7 +4,7 @@ download_path =
|
|||||||
[chrome_options]
|
[chrome_options]
|
||||||
debugger_address = 127.0.0.1:9222
|
debugger_address = 127.0.0.1:9222
|
||||||
browser_path = chrome
|
browser_path = chrome
|
||||||
arguments = ['--remote-allow-origins=*', '--no-first-run', '--disable-infobars', '--disable-popup-blocking']
|
arguments = ['--no-first-run', '--disable-infobars', '--disable-popup-blocking']
|
||||||
extensions = []
|
extensions = []
|
||||||
prefs = {'profile.default_content_settings.popups': 0, 'profile.default_content_setting_values': {'notifications': 2}}
|
prefs = {'profile.default_content_settings.popups': 0, 'profile.default_content_setting_values': {'notifications': 2}}
|
||||||
flags = {}
|
flags = {}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user