From d6402c26c8ff98986ec05b357c2b14a57690f572 Mon Sep 17 00:00:00 2001 From: g1879 Date: Wed, 13 Nov 2024 16:13:57 +0800 Subject: [PATCH] =?UTF-8?q?4.1.0.12=E4=BF=AE=E5=A4=8D=E6=97=A0=E6=B3=95?= =?UTF-8?q?=E5=A4=84=E7=90=86=E8=BF=9E=E7=BB=AD=E5=BC=B9=E6=A1=86=E9=97=AE?= =?UTF-8?q?=E9=A2=98=EF=BC=9B=E4=BF=AE=E5=A4=8D=E6=96=B0=E5=BB=BAtab?= =?UTF-8?q?=E5=8F=AF=E8=83=BD=E5=87=BA=E7=8E=B0=E7=9A=84=E9=97=AE=E9=A2=98?= =?UTF-8?q?=EF=BC=9B=E6=8C=87=E5=AE=9Atldextract=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DrissionPage/__init__.py | 2 +- DrissionPage/_base/chromium.py | 12 ++++++------ DrissionPage/_pages/chromium_base.py | 6 +++--- DrissionPage/_pages/chromium_base.pyi | 10 ++++++++-- requirements.txt | 2 +- setup.py | 2 +- 6 files changed, 20 insertions(+), 14 deletions(-) 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=[