From 7dc8650b37abbcbe3d2afbcc3f829b13e83d5631 Mon Sep 17 00:00:00 2001 From: g1879 Date: Wed, 22 Mar 2023 22:50:04 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0wait.new=5Ftab()=EF=BC=9B?= =?UTF-8?q?=E4=BF=AE=E5=A4=8Dcookie=E8=A7=A3=E6=9E=90=E7=9A=84=E4=B8=80?= =?UTF-8?q?=E4=B8=AA=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DrissionPage/chromium_base.py | 4 ++-- DrissionPage/chromium_page.py | 12 +++++++++++- DrissionPage/chromium_page.pyi | 2 ++ DrissionPage/commons/web.py | 2 +- 4 files changed, 16 insertions(+), 4 deletions(-) diff --git a/DrissionPage/chromium_base.py b/DrissionPage/chromium_base.py index caa52c8..1e25da5 100644 --- a/DrissionPage/chromium_base.py +++ b/DrissionPage/chromium_base.py @@ -42,8 +42,8 @@ class ChromiumBase(BasePage): self._set = None self._screencast = None - if isinstance(address, int) or address.isdigit(): - address = f'localhost:{address}' + if address and (isinstance(address, int) or address.isdigit()): + address = f'127.0.0.1:{address}' self._set_start_options(address, None) self._set_runtime_settings() diff --git a/DrissionPage/chromium_page.py b/DrissionPage/chromium_page.py index 2d0b939..821bbb4 100644 --- a/DrissionPage/chromium_page.py +++ b/DrissionPage/chromium_page.py @@ -399,6 +399,16 @@ class ChromiumPageWaiter(ChromiumBaseWaiter): """ return self._driver.download_set.wait_download_begin(timeout) + def new_tab(self, timeout=None): + """等待新标签页出现 + :param timeout: 等待超时时间,为None则使用页面对象timeout属性 + :return: 是否等到下载开始 + """ + timeout = timeout if timeout is not None else self._driver.timeout + end_time = perf_counter() + timeout + while self._driver.tab_id == self._driver.latest_tab and perf_counter() < end_time: + sleep(.01) + class ChromiumTabRect(object): def __init__(self, page): @@ -721,7 +731,7 @@ def show_or_hide_browser(page, hide=True): :param hide: 是否隐藏 :return: None """ - if not page.address.startswith(('localhost', '127.0.0.1')): + if not page.address.startswith(('127.0.0.1', 'localhost')): return if system().lower() != 'windows': diff --git a/DrissionPage/chromium_page.pyi b/DrissionPage/chromium_page.pyi index 3444917..4d63200 100644 --- a/DrissionPage/chromium_page.pyi +++ b/DrissionPage/chromium_page.pyi @@ -111,6 +111,8 @@ class ChromiumPageWaiter(ChromiumBaseWaiter): def download_begin(self, timeout: float = None) -> bool: ... + def new_tab(self, timeout: float = None) -> bool: ... + class ChromiumTabRect(object): def __init__(self, page: ChromiumPage): diff --git a/DrissionPage/commons/web.py b/DrissionPage/commons/web.py index 0fcc61b..6c3dc42 100644 --- a/DrissionPage/commons/web.py +++ b/DrissionPage/commons/web.py @@ -183,7 +183,7 @@ def cookie_to_dict(cookie): cookie_dict = {} for key, attr in enumerate(cookie): - attr_val = attr.lstrip().split('=') + attr_val = attr.lstrip().split('=', 1) if key == 0: cookie_dict['name'] = attr_val[0]