mirror of
https://gitee.com/g1879/DrissionPage.git
synced 2024-12-10 04:00:23 +08:00
完善启动chrome逻辑
This commit is contained in:
parent
c6d5254826
commit
fa847ffb9b
@ -96,19 +96,31 @@ class Drission(object):
|
|||||||
|
|
||||||
if options.debugger_address and _check_port(options.debugger_address) is False:
|
if options.debugger_address and _check_port(options.debugger_address) is False:
|
||||||
from subprocess import Popen
|
from subprocess import Popen
|
||||||
port = options.debugger_address.split(':')[-1]
|
port = options.debugger_address[options.debugger_address.rfind(':') + 1:]
|
||||||
|
|
||||||
|
try:
|
||||||
Popen(f'{chrome_path} --remote-debugging-port={port}', shell=False)
|
Popen(f'{chrome_path} --remote-debugging-port={port}', shell=False)
|
||||||
|
|
||||||
|
except FileNotFoundError:
|
||||||
|
from DrissionPage.easy_set import _get_chrome_path
|
||||||
|
|
||||||
|
chrome_path = _get_chrome_path(show_msg=False)
|
||||||
|
|
||||||
|
if not chrome_path:
|
||||||
|
raise FileNotFoundError('无法找到chrome.exe路径,请手动配置。')
|
||||||
|
|
||||||
|
Popen(f'"{chrome_path}" --remote-debugging-port={port}', shell=False)
|
||||||
|
options.binary_location = chrome_path
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self._driver = webdriver.Chrome(driver_path, options=options)
|
self._driver = webdriver.Chrome(driver_path, options=options)
|
||||||
|
|
||||||
except (WebDriverException, SessionNotCreatedException):
|
except (WebDriverException, SessionNotCreatedException):
|
||||||
from .easy_set import get_match_driver
|
from .easy_set import get_match_driver
|
||||||
|
|
||||||
chrome_path = self._driver_options.get('binary_location', None) or None
|
|
||||||
print('自动下载chromedriver...')
|
print('自动下载chromedriver...')
|
||||||
driver_path = get_match_driver(chrome_path=chrome_path, check_version=False, show_msg=False)
|
chrome_path = None if chrome_path == 'chrome.exe' else chrome_path
|
||||||
|
driver_path = get_match_driver(chrome_path=chrome_path, check_version=False)
|
||||||
|
|
||||||
if driver_path:
|
if driver_path:
|
||||||
try:
|
try:
|
||||||
@ -326,7 +338,7 @@ class Drission(object):
|
|||||||
|
|
||||||
|
|
||||||
def _check_port(debugger_address: str) -> Union[bool, None]:
|
def _check_port(debugger_address: str) -> Union[bool, None]:
|
||||||
"""检查端口是否可用 \n
|
"""检查端口是否被占用 \n
|
||||||
:param debugger_address: 浏览器地址及端口
|
:param debugger_address: 浏览器地址及端口
|
||||||
:return: bool
|
:return: bool
|
||||||
"""
|
"""
|
||||||
@ -345,3 +357,6 @@ def _check_port(debugger_address: str) -> Union[bool, None]:
|
|||||||
return True
|
return True
|
||||||
except socket.error:
|
except socket.error:
|
||||||
return False
|
return False
|
||||||
|
finally:
|
||||||
|
if s:
|
||||||
|
s.close()
|
||||||
|
@ -208,11 +208,11 @@ def get_match_driver(ini_path: Union[str, None] = 'default',
|
|||||||
chrome_path = chrome_path or _get_chrome_path(ini_path, show_msg)
|
chrome_path = chrome_path or _get_chrome_path(ini_path, show_msg)
|
||||||
chrome_path = Path(chrome_path).absolute() if chrome_path else None
|
chrome_path = Path(chrome_path).absolute() if chrome_path else None
|
||||||
if show_msg:
|
if show_msg:
|
||||||
print('chrome.exe路径', chrome_path, '\n')
|
print('chrome.exe路径', chrome_path)
|
||||||
|
|
||||||
ver = _get_chrome_version(chrome_path)
|
ver = _get_chrome_version(chrome_path)
|
||||||
if show_msg:
|
if show_msg:
|
||||||
print('version', ver, '\n')
|
print('version', ver)
|
||||||
|
|
||||||
zip_path = _download_driver(ver, save_path, show_msg=show_msg)
|
zip_path = _download_driver(ver, save_path, show_msg=show_msg)
|
||||||
|
|
||||||
@ -225,7 +225,7 @@ def get_match_driver(ini_path: Union[str, None] = 'default',
|
|||||||
driver_path = None
|
driver_path = None
|
||||||
|
|
||||||
if show_msg:
|
if show_msg:
|
||||||
print('\n解压路径', driver_path, '\n')
|
print('解压路径', driver_path)
|
||||||
|
|
||||||
if driver_path:
|
if driver_path:
|
||||||
Path(zip_path).unlink()
|
Path(zip_path).unlink()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user