From 0ebcebc48215d3156d162b17fa9dca72a6b31d5c Mon Sep 17 00:00:00 2001 From: g1879 Date: Thu, 23 Sep 2021 14:01:42 +0800 Subject: [PATCH] 1.11.3 --- DrissionPage/config.py | 16 +++++++++++----- DrissionPage/configs.ini | 16 ++++++++-------- DrissionPage/drission.py | 4 ++-- DrissionPage/mix_page.py | 4 +++- setup.py | 2 +- 5 files changed, 25 insertions(+), 17 deletions(-) diff --git a/DrissionPage/config.py b/DrissionPage/config.py index 971984b..369ace2 100644 --- a/DrissionPage/config.py +++ b/DrissionPage/config.py @@ -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') diff --git a/DrissionPage/configs.ini b/DrissionPage/configs.ini index 1185031..21eee64 100644 --- a/DrissionPage/configs.ini +++ b/DrissionPage/configs.ini @@ -1,19 +1,19 @@ [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']} [session_options] headers = { - "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/603.3.8 (KHTML, like Gecko) Version/10.1.2 Safari/603.3.8", - "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", - "Connection": "keep-alive", - "Accept-Charset": "GB2312,utf-8;q=0.7,*;q=0.7" - } + "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/603.3.8 (KHTML, like Gecko) Version/10.1.2 Safari/603.3.8", + "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", + "Connection": "keep-alive", + "Accept-Charset": "GB2312,utf-8;q=0.7,*;q=0.7" + } diff --git a/DrissionPage/drission.py b/DrissionPage/drission.py index 33f5f47..c583e5e 100644 --- a/DrissionPage/drission.py +++ b/DrissionPage/drission.py @@ -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 diff --git a/DrissionPage/mix_page.py b/DrissionPage/mix_page.py index 39ae39b..dfced89 100644 --- a/DrissionPage/mix_page.py +++ b/DrissionPage/mix_page.py @@ -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], diff --git a/setup.py b/setup.py index c64fa4d..a6e1113 100644 --- a/setup.py +++ b/setup.py @@ -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.",