diff --git a/DrissionPage/__init__.py b/DrissionPage/__init__.py index ce59302..5d6762d 100644 --- a/DrissionPage/__init__.py +++ b/DrissionPage/__init__.py @@ -12,4 +12,4 @@ from ._pages.chromium_page import ChromiumPage from ._pages.session_page import SessionPage from ._pages.web_page import WebPage -__version__ = '4.1.0.11' +__version__ = '4.1.0.12' diff --git a/DrissionPage/_base/chromium.py b/DrissionPage/_base/chromium.py index e89d88b..abf6b57 100644 --- a/DrissionPage/_base/chromium.py +++ b/DrissionPage/_base/chromium.py @@ -294,7 +294,7 @@ class Chromium(object): rmtree(path, True) def _new_tab(self, mix=True, url=None, new_window=False, background=False, new_context=False): - obj = MixTab if mix else ChromiumTab + tab_type = MixTab if mix else ChromiumTab tab = None if new_context: tab = self._run_cdp('Target.createBrowserContext')['browserContextId'] @@ -308,12 +308,12 @@ class Chromium(object): kwargs['browserContextId'] = tab if self.states.is_incognito: - return _new_tab_by_js(self, url, obj, new_window) + return _new_tab_by_js(self, url, tab_type, new_window) else: try: tab = self._run_cdp('Target.createTarget', **kwargs)['targetId'] except CDPError: - return _new_tab_by_js(self, url, obj, new_window) + return _new_tab_by_js(self, url, tab_type, new_window) while self.states.is_alive: if tab in self._drivers: @@ -321,7 +321,7 @@ class Chromium(object): sleep(.1) else: raise BrowserConnectError('浏览器已关闭') - tab = obj(self, tab) + tab = tab_type(self, tab) if url: tab.get(url) return tab @@ -484,8 +484,8 @@ def run_browser(chromium_options): return is_headless, browser_id, is_exists -def _new_tab_by_js(browser: Chromium, url, obj, new_window): - mix = isinstance(obj, MixTab) +def _new_tab_by_js(browser: Chromium, url, tab_type, new_window): + mix = tab_type == MixTab tab = browser._get_tab(mix=mix) if url and not match(r'^.*?://.*', url): raise ValueError(f'url也许需要加上http://?') diff --git a/DrissionPage/_pages/chromium_base.py b/DrissionPage/_pages/chromium_base.py index 685caa1..cf807be 100644 --- a/DrissionPage/_pages/chromium_base.py +++ b/DrissionPage/_pages/chromium_base.py @@ -673,11 +673,11 @@ class ChromiumBase(BasePage): self._get_document() def handle_alert(self, accept=True, send=None, timeout=None, next_one=False): - r = self._handle_alert(accept=accept, send=send, timeout=timeout, next_one=next_one) if not isinstance(accept, bool): - return r + return self._handle_alert(accept=accept, send=send, timeout=timeout, next_one=next_one) + r = self._handle_alert(accept=accept, send=send, timeout=timeout, next_one=next_one) while self._has_alert: - sleep(.1) + sleep(.0001) return r def _handle_alert(self, accept=True, send=None, timeout=None, next_one=False): diff --git a/DrissionPage/_pages/chromium_base.pyi b/DrissionPage/_pages/chromium_base.pyi index 335f5ee..b7bc592 100644 --- a/DrissionPage/_pages/chromium_base.pyi +++ b/DrissionPage/_pages/chromium_base.pyi @@ -573,7 +573,10 @@ class ChromiumBase(BasePage): """ ... - def handle_alert(self, accept: Optional[bool] = True, send: str = None, timeout: float = None, + def handle_alert(self, + accept: Optional[bool] = True, + send: str = None, + timeout: float = None, next_one: bool = False) -> Union[str, False]: """处理提示框,可以自动等待提示框出现 :param accept: True表示确认,False表示取消,为None不会按按钮但依然返回文本值 @@ -584,7 +587,10 @@ class ChromiumBase(BasePage): """ ... - def _handle_alert(self, accept: bool = True, send: str = None, timeout: float = None, + def _handle_alert(self, + accept: Optional[bool] = True, + send: str = None, + timeout: float = None, next_one: bool = False) -> Union[str, False]: """处理提示框,可以自动等待提示框出现 :param accept: True表示确认,False表示取消,其它值不会按按钮但依然返回文本值 diff --git a/requirements.txt b/requirements.txt index 5706df4..3713b42 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,5 +4,5 @@ cssselect DownloadKit>=2.0.5 websocket-client click -tldextract +tldextract>=3.4.4 psutil \ No newline at end of file diff --git a/setup.py b/setup.py index b846836..5e7b984 100644 --- a/setup.py +++ b/setup.py @@ -26,7 +26,7 @@ setup( 'DownloadKit>=2.0.5', 'websocket-client', 'click', - 'tldextract', + 'tldextract>=3.4.4', 'psutil' ], classifiers=[