From cf8e00bb94e582cc42e1ab528435cae9671e85e8 Mon Sep 17 00:00:00 2001 From: g1879 Date: Wed, 18 Jan 2023 11:13:15 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=96=B0=E6=B5=8F=E8=A7=88?= =?UTF-8?q?=E5=99=A8=E7=AC=AC=E4=B8=80=E6=AC=A1=E6=96=B0=E5=BB=BA=E6=A0=87?= =?UTF-8?q?=E7=AD=BE=E9=A1=B5=E6=97=B6=E4=B8=8D=E6=AD=A3=E7=A1=AE=E5=88=87?= =?UTF-8?q?=E6=8D=A2=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DrissionPage/chromium_page.py | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/DrissionPage/chromium_page.py b/DrissionPage/chromium_page.py index 56e1ee8..1977512 100644 --- a/DrissionPage/chromium_page.py +++ b/DrissionPage/chromium_page.py @@ -22,7 +22,7 @@ class ChromiumPage(ChromiumBase): """用于管理浏览器的类""" def __init__(self, addr_driver_opts=None, tab_id=None, timeout=None): - """初始化 \n + """ :param addr_driver_opts: 浏览器地址:端口、ChromiumDriver对象或DriverOptions对象 :param tab_id: 要控制的标签页id,不指定默认为激活的 :param timeout: 超时时间 @@ -30,7 +30,7 @@ class ChromiumPage(ChromiumBase): super().__init__(addr_driver_opts, tab_id, timeout) def _connect_browser(self, addr_driver_opts=None, tab_id=None): - """连接浏览器,在第一次时运行 \n + """连接浏览器,在第一次时运行 \n :param addr_driver_opts: 浏览器地址、ChromiumDriver对象或DriverOptions对象 :param tab_id: 要控制的标签页id,不指定默认为激活的 :return: None @@ -208,22 +208,25 @@ class ChromiumPage(ChromiumBase): :return: None """ if switch_to: - begin_len = len(self.tabs) - self._control_session.get(f'http://{self.address}/json/new') + begin_tabs = set(self.tabs) + len_tabs = len(begin_tabs) + self.run_cdp('Target.createTarget', url='') tabs = self.tabs - while len(tabs) <= begin_len: + while len(tabs) == len_tabs: tabs = self.tabs + sleep(.005) - self._to_tab(tabs[0], read_doc=False) + new_tab = set(tabs) - begin_tabs + self._to_tab(new_tab.pop(), read_doc=False) if url: self.get(url) elif url: - self._control_session.get(f'http://{self.address}/json/new?{url}') + self.run_cdp('Target.createTarget', url=url) else: - self._control_session.get(f'http://{self.address}/json/new') + self.run_cdp('Target.createTarget', url='') def set_main_tab(self, tab_id=None): """设置主tab \n