From 294e5219c74d7c84bba5a77d09f3afbf36b84c23 Mon Sep 17 00:00:00 2001 From: g1879 Date: Fri, 8 Dec 2023 18:31:51 +0800 Subject: [PATCH] =?UTF-8?q?ChromiumOptions=E5=A2=9E=E5=8A=A0incognito()?= =?UTF-8?q?=E6=96=B9=E6=B3=95=EF=BC=9Bini=E6=96=87=E4=BB=B6=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E5=87=A0=E4=B8=AA=E5=90=AF=E5=8A=A8=E5=8F=82=E6=95=B0?= =?UTF-8?q?=EF=BC=9Bcookie=E8=AE=BE=E7=BD=AE=E6=97=B6value=E9=BB=98?= =?UTF-8?q?=E8=AE=A4=E4=B8=BAstr=EF=BC=9B=E4=BF=AE=E5=A4=8Ddriver=E6=8A=A5?= =?UTF-8?q?=E9=94=99=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DrissionPage/_base/chromium_driver.py | 5 ++--- DrissionPage/_commons/web.py | 2 ++ DrissionPage/_configs/chromium_options.py | 8 ++++++++ DrissionPage/_configs/chromium_options.pyi | 2 ++ DrissionPage/_configs/configs.ini | 2 +- 5 files changed, 15 insertions(+), 4 deletions(-) diff --git a/DrissionPage/_base/chromium_driver.py b/DrissionPage/_base/chromium_driver.py index 44f3e8b..422eeb4 100644 --- a/DrissionPage/_base/chromium_driver.py +++ b/DrissionPage/_base/chromium_driver.py @@ -9,8 +9,7 @@ from threading import Thread, Event from time import perf_counter from requests import get -from websocket import (WebSocketTimeoutException, WebSocketException, WebSocketConnectionClosedException, - create_connection) +from websocket import WebSocketTimeoutException, WebSocketConnectionClosedException, create_connection class ChromiumDriver(object): @@ -103,7 +102,7 @@ class ChromiumDriver(object): msg = loads(msg_json) except WebSocketTimeoutException: continue - except (WebSocketException, OSError, WebSocketConnectionClosedException): + except: self.stop() return diff --git a/DrissionPage/_commons/web.py b/DrissionPage/_commons/web.py index a94bacf..030c181 100644 --- a/DrissionPage/_commons/web.py +++ b/DrissionPage/_commons/web.py @@ -266,6 +266,8 @@ def set_browser_cookies(page, cookies): '%a, %d %b %y %H:%M:%S GMT').timestamp() if cookie['value'] is None: cookie['value'] = '' + elif not isinstance(cookie['value'], str): + cookie['value'] = str(cookie['value']) if cookie['name'].startswith('__Secure-'): cookie['secure'] = True diff --git a/DrissionPage/_configs/chromium_options.py b/DrissionPage/_configs/chromium_options.py index b8e2eec..fca7805 100644 --- a/DrissionPage/_configs/chromium_options.py +++ b/DrissionPage/_configs/chromium_options.py @@ -340,6 +340,14 @@ class ChromiumOptions(object): on_off = None if on_off else False return self.set_argument('--mute-audio', on_off) + def incognito(self, on_off=True): + """设置是否使用无痕模式启动 + :param on_off: 开或关 + :return: 当前对象 + """ + on_off = None if on_off else False + return self.set_argument('--incognito', on_off) + def ignore_certificate_errors(self, on_off=True): """设置是否忽略证书错误 :param on_off: 开或关 diff --git a/DrissionPage/_configs/chromium_options.pyi b/DrissionPage/_configs/chromium_options.pyi index ec843ca..8398182 100644 --- a/DrissionPage/_configs/chromium_options.pyi +++ b/DrissionPage/_configs/chromium_options.pyi @@ -113,6 +113,8 @@ class ChromiumOptions(object): def mute(self, on_off: bool = True) -> ChromiumOptions: ... + def incognito(self, on_off: bool = True) -> ChromiumOptions: ... + def set_user_agent(self, user_agent: str) -> ChromiumOptions: ... def set_proxy(self, proxy: str) -> ChromiumOptions: ... diff --git a/DrissionPage/_configs/configs.ini b/DrissionPage/_configs/configs.ini index 7a22f7a..4355442 100644 --- a/DrissionPage/_configs/configs.ini +++ b/DrissionPage/_configs/configs.ini @@ -4,7 +4,7 @@ download_path = [chromium_options] address = 127.0.0.1:9222 browser_path = chrome -arguments = ['--no-first-run', '--disable-infobars', '--disable-popup-blocking'] +arguments = ['--no-default-browser-check', '--disable-suggestions-ui', '--no-first-run', '--disable-infobars', '--disable-popup-blocking'] extensions = [] prefs = {'profile.default_content_settings.popups': 0, 'profile.default_content_setting_values': {'notifications': 2}} flags = {}