ChromiumOptions增加incognito()方法;ini文件增加几个启动参数;cookie设置时value默认为str;修复driver报错问题

This commit is contained in:
g1879 2023-12-08 18:31:51 +08:00
parent cee5af6d7e
commit 294e5219c7
5 changed files with 15 additions and 4 deletions

View File

@ -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

View File

@ -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

View File

@ -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: 开或关

View File

@ -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: ...

View File

@ -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 = {}