From 4a5c977a0717968d319369055dc8408eab1dc519 Mon Sep 17 00:00:00 2001 From: g1879 Date: Mon, 12 Apr 2021 15:49:24 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BB=BA=E7=AB=8B=E8=B0=83=E8=AF=95=E6=B5=8F?= =?UTF-8?q?=E8=A7=88=E5=99=A8=E6=97=B6=E4=BC=9A=E5=8A=A0=E5=85=A5=E8=AE=BE?= =?UTF-8?q?=E7=BD=AE=E9=A1=B9=EF=BC=9B=E5=A2=9E=E5=8A=A0kill=5Fbrowser()?= =?UTF-8?q?=E6=96=B9=E6=B3=95=E3=80=82=E5=BE=85=E6=B5=8B=E8=AF=95=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DrissionPage/drission.py | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/DrissionPage/drission.py b/DrissionPage/drission.py index 214837f..217fb0a 100644 --- a/DrissionPage/drission.py +++ b/DrissionPage/drission.py @@ -98,9 +98,12 @@ class Drission(object): if options.debugger_address and _check_port(options.debugger_address) is False: from subprocess import Popen port = options.debugger_address[options.debugger_address.rfind(':') + 1:] + args = ' '.join(self._driver_options['arguments']) + if self._proxy: + args = f'{args} --proxy-server={self._proxy["http"]}' try: - self._debugger = Popen(f'{chrome_path} --remote-debugging-port={port}', shell=False) + self._debugger = Popen(f'{chrome_path} --remote-debugging-port={port} {args}', shell=False) if chrome_path == 'chrome.exe': from common import get_exe_path_from_port @@ -114,7 +117,7 @@ class Drission(object): if not chrome_path: raise FileNotFoundError('无法找到chrome.exe路径,请手动配置。') - self._debugger = Popen(f'"{chrome_path}" --remote-debugging-port={port}', shell=False) + self._debugger = Popen(f'"{chrome_path}" --remote-debugging-port={port} {args}', shell=False) # -----------创建WebDriver对象----------- try: @@ -165,11 +168,6 @@ class Drission(object): return self._driver - @property - def debugger_progress(self): - """调试浏览器进程""" - return self._debugger - @property def driver_options(self) -> dict: """返回driver配置信息""" @@ -216,6 +214,16 @@ class Drission(object): for cookie in cookies: self.set_cookies(cookie, set_driver=True) + @property + def debugger_progress(self): + """调试浏览器进程""" + return self._debugger + + def kill_browser(self): + """关闭浏览器进程(如果可以)""" + if self.debugger_progress: + self.debugger_progress.kill() + def set_cookies(self, cookies: Union[RequestsCookieJar, list, tuple, str, dict], set_session: bool = False,