This commit is contained in:
g1879 2021-09-23 14:01:42 +08:00
parent ff91b76065
commit 0ebcebc482
5 changed files with 25 additions and 17 deletions

View File

@ -268,7 +268,7 @@ class SessionOptions(object):
:param headers: 参数值
:return: None
"""
self._headers = {key.lower(): headers[key] for key in headers}
self.set_headers(headers)
@cookies.setter
def cookies(self, cookies: Union[RequestsCookieJar, list, tuple, str, dict]) -> None:
@ -679,12 +679,15 @@ def _dict_to_chrome_options(options: dict) -> Options:
return chrome_options
def _chrome_options_to_dict(options: Union[dict, DriverOptions, Options, None]) -> Union[dict, None]:
def _chrome_options_to_dict(options: Union[dict, DriverOptions, Options, None, bool]) -> Union[dict, None]:
"""把chrome配置对象转换为字典 \n
:param options: chrome配置对象字典或DriverOptions对象
:return: 配置字典
"""
if isinstance(options, (dict, type(None))):
if options in (False, None):
return DriverOptions(read_file=False).as_dict()
if isinstance(options, dict):
return options
re_dict = dict()
@ -702,7 +705,10 @@ def _session_options_to_dict(options: Union[dict, SessionOptions, None]) -> Unio
:param options: session配置对象或字典
:return: 配置字典
"""
if isinstance(options, (dict, type(None))):
if options in (False, None):
return SessionOptions(read_file=False).as_dict()
if isinstance(options, dict):
return options
re_dict = dict()
@ -718,7 +724,7 @@ def _session_options_to_dict(options: Union[dict, SessionOptions, None]) -> Unio
if val is not None:
re_dict[attr] = val
# cert属性默认值为None免无法区分是否被设置,故主动赋值
# cert属性默认值为None免无法区分是否被设置,故主动赋值
re_dict['cert'] = options.__getattribute__('_cert')
re_dict['auth'] = options.__getattribute__('_auth')

View File

@ -1,10 +1,10 @@
[paths]
chromedriver_path = D:\python\projects\DrissionPage\DrissionPage\chromedriver.exe
tmp_path = D:\python\projects\DrissionPage\DrissionPage\tmp
chromedriver_path =
tmp_path =
[chrome_options]
debugger_address =
binary_location = d:\python\google chrome\chrome\chrome.exe
binary_location =
arguments = ['--no-sandbox', '--disable-gpu', '--ignore-certificate-errors', '--disable-infobars']
extensions = []
experimental_options = {'prefs': {'profile.default_content_settings.popups': 0, 'profile.default_content_setting_values': {'notifications': 2}, 'plugins.plugins_list': [{'enabled': False, 'name': 'Chrome PDF Viewer'}]}, 'useAutomationExtension': False, 'excludeSwitches': ['enable-automation']}

View File

@ -23,8 +23,8 @@ class Drission(object):
"""Drission类用于管理WebDriver对象和Session对象是驱动器的角色"""
def __init__(self,
driver_or_options: Union[WebDriver, dict, Options, DriverOptions] = None,
session_or_options: Union[Session, dict, SessionOptions] = None,
driver_or_options: Union[WebDriver, dict, Options, DriverOptions, bool] = None,
session_or_options: Union[Session, dict, SessionOptions, bool] = None,
ini_path: str = None,
proxy: dict = None):
"""初始化可接收现成的WebDriver和Session对象或接收它们的配置信息生成对象 \n

View File

@ -41,10 +41,12 @@ class MixPage(SessionPage, DriverPage, BasePage):
:param driver_options: 浏览器设置没有传入drission参数时会用这个设置新建Drission对象
:param session_options: requests设置没有传入drission参数时会用这个设置新建Drission对象
"""
super().__init__(timeout) # BasePage的__init__()
super(DriverPage, self).__init__(timeout) # BasePage的__init__()
self._mode = mode.lower()
self._driver, self._session = (None, True) if self._mode == 's' else (True, None)
self._drission = drission or Drission(driver_options, session_options)
self._wait_object = None
self._response = None
def __call__(self,
loc_or_str: Union[Tuple[str, str], str, DriverElement, SessionElement, WebElement],

View File

@ -6,7 +6,7 @@ with open("README.md", "r", encoding='utf-8') as fh:
setup(
name="DrissionPage",
version="1.11.0",
version="1.11.3",
author="g1879",
author_email="g1879@qq.com",
description="A module that integrates selenium and requests session, encapsulates common page operations.",