diff --git a/DrissionPage/__init__.py b/DrissionPage/__init__.py index 098d123..8631fbb 100644 --- a/DrissionPage/__init__.py +++ b/DrissionPage/__init__.py @@ -13,4 +13,4 @@ from ._configs.chromium_options import ChromiumOptions from ._configs.session_options import SessionOptions __all__ = ['ChromiumPage', 'ChromiumOptions', 'SessionOptions', 'SessionPage', 'WebPage', '__version__'] -__version__ = '4.0.0b29' +__version__ = '4.0.0b30' diff --git a/DrissionPage/_base/browser.py b/DrissionPage/_base/browser.py index 2d8b891..2171bd1 100644 --- a/DrissionPage/_base/browser.py +++ b/DrissionPage/_base/browser.py @@ -92,8 +92,9 @@ class Browser(object): :param cmd_args: 参数 :return: 执行的结果 """ + ignore = cmd_args.pop('_ignore', None) r = self._driver.run(cmd, **cmd_args) - return r if __ERROR__ not in r else raise_error(r) + return r if __ERROR__ not in r else raise_error(r, ignore) @property def driver(self): diff --git a/DrissionPage/_pages/chromium_base.py b/DrissionPage/_pages/chromium_base.py index eb21aee..025ab24 100644 --- a/DrissionPage/_pages/chromium_base.py +++ b/DrissionPage/_pages/chromium_base.py @@ -143,7 +143,7 @@ class ChromiumBase(BasePage): self._driver.set_callback('Page.loadEventFired', self._onLoadEventFired) self._driver.set_callback('Page.frameStoppedLoading', self._onFrameStoppedLoading) self._driver.set_callback('Page.frameAttached', self._onFrameAttached) - self._driver.set_callback('Page.frameDetached', self._onFrameDetached) + self._driver.set_callback('Page.frameDetached', self._onFrameDetached, immediate=True) def _get_document(self, timeout=10): """获取页面文档 diff --git a/DrissionPage/_pages/chromium_frame.py b/DrissionPage/_pages/chromium_frame.py index f2d8820..b8f09cb 100644 --- a/DrissionPage/_pages/chromium_frame.py +++ b/DrissionPage/_pages/chromium_frame.py @@ -95,7 +95,7 @@ class ChromiumFrame(ChromiumBase): except: self.browser.driver.get(f'http://{self.address}/json') super()._driver_init(tab_id) - self._driver.set_callback('Inspector.detached', self._onInspectorDetached) + self._driver.set_callback('Inspector.detached', self._onInspectorDetached, immediate=True) def _reload(self): """重新获取document""" @@ -136,19 +136,23 @@ class ChromiumFrame(ChromiumBase): self._is_diff_domain = True if self._listener: self._listener._to_target(node['frameId'], self.address, self) - super().__init__(self.address, node['frameId'], self._target_page.timeout) end_time = perf_counter() + self.timeouts.page_load - while perf_counter() < end_time: - try: - obj_id = super().run_js('document;', as_expr=True)['objectId'] - self.doc_ele = ChromiumElement(self, obj_id=obj_id) - break - except Exception as e: - sleep(.1) - if self._debug: - print(f'获取doc失败,重试 {e}') - else: - raise GetDocumentError + super().__init__(self.address, node['frameId'], self._target_page.timeout) + timeout = end_time - perf_counter() + if timeout <= 0: + timeout = .5 + self._wait_loaded(timeout) + # while perf_counter() < end_time: + # try: + # obj_id = super().run_js('document;', as_expr=True)['objectId'] + # self.doc_ele = ChromiumElement(self, obj_id=obj_id) + # break + # except Exception as e: + # sleep(.1) + # if self._debug: + # print(f'获取doc失败,重试 {e}') + # else: + # raise GetDocumentError self._debug = debug self.driver._debug = d_debug @@ -201,26 +205,14 @@ class ChromiumFrame(ChromiumBase): def _onInspectorDetached(self, **kwargs): """异域转同域或退出""" - if self._debug: - print(f'{self._frame_id}触发InspectorDetached') - self._reload() - if self._debug: - print(f'{self._frame_id}执行InspectorDetached完毕') - def _onFrameDetached(self, **kwargs): """同域变异域""" self.browser._frames.pop(kwargs['frameId'], None) if kwargs['frameId'] == self._frame_id: - if self._debug: - print(f'{self._frame_id}触发FrameDetached') - self._reload() - if self._debug: - print(f'{self._frame_id}执行FrameDetached完毕') - # ----------挂件---------- @property diff --git a/DrissionPage/_units/selector.py b/DrissionPage/_units/selector.py index 8d945d2..e7a84d3 100644 --- a/DrissionPage/_units/selector.py +++ b/DrissionPage/_units/selector.py @@ -252,7 +252,7 @@ class SelectElement(object): """ if isinstance(option, (list, tuple, set)): if not self.is_multi and len(option) > 1: - raise TypeError("只能对多项选框执行多选。") + option = option[:1] for o in option: o.run_js(f'this.selected={mode};') self._dispatch_change() diff --git a/requirements.txt b/requirements.txt index 57cde23..e02789b 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,7 +1,7 @@ requests lxml cssselect -DownloadKit>=2.0.0b2 +DownloadKit>=2.0.0b3 websocket-client>=1.7.0 click tldextract diff --git a/setup.py b/setup.py index 66aeaf1..784d826 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="4.0.0b29", + version="4.0.0b30", author="g1879", author_email="g1879@qq.com", description="Python based web automation tool. It can control the browser and send and receive data packets.", @@ -22,19 +22,19 @@ setup( 'lxml', 'requests', 'cssselect', - 'DownloadKit>=2.0.0b2', + 'DownloadKit>=2.0.0b3', 'websocket-client>=1.7.0', 'click', 'tldextract', 'psutil' ], classifiers=[ - "Programming Language :: Python :: 3.8", + "Programming Language :: Python :: 3.6", "Development Status :: 4 - Beta", "Topic :: Utilities", "License :: OSI Approved :: BSD License", ], - python_requires='>=3.8', + python_requires='>=3.6', entry_points={ 'console_scripts': [ 'dp = DrissionPage.commons.cli:main',