From 07d32a1f87fa35124d6a33c3a2a0da7fb0434259 Mon Sep 17 00:00:00 2001 From: g1879 Date: Fri, 7 Apr 2023 20:07:59 +0800 Subject: [PATCH] =?UTF-8?q?3.2.26find=5Ftabs()=E5=A2=9E=E5=8A=A0special?= =?UTF-8?q?=E5=8F=82=E6=95=B0=EF=BC=9B=E4=BF=AE=E5=A4=8D=E6=A0=87=E7=AD=BE?= =?UTF-8?q?=E9=A1=B5=E5=AF=B9=E8=B1=A1=E5=86=85=E5=85=83=E7=B4=A0=E6=97=A0?= =?UTF-8?q?=E6=B3=95=E8=8E=B7=E5=8F=96=E5=B1=8F=E5=B9=95=E5=9D=90=E6=A0=87?= =?UTF-8?q?=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 | 15 +++++++++------ DrissionPage/chromium_page.pyi | 3 ++- DrissionPage/chromium_tab.py | 5 +++++ DrissionPage/chromium_tab.pyi | 5 ++++- setup.py | 2 +- 5 files changed, 21 insertions(+), 9 deletions(-) diff --git a/DrissionPage/chromium_page.py b/DrissionPage/chromium_page.py index b52de76..d0e9f7b 100644 --- a/DrissionPage/chromium_page.py +++ b/DrissionPage/chromium_page.py @@ -194,19 +194,22 @@ class ChromiumPage(ChromiumBase): tab_id = tab_id or self.tab_id return ChromiumTab(self, tab_id) - def find_tabs(self, text, by_title=True, by_url=None): + def find_tabs(self, text=None, by_title=True, by_url=None, special=False): """查找符合条件的tab,返回它们的id组成的列表 :param text: 查询条件 :param by_title: 是否匹配title :param by_url: 是否匹配url + :param special: 是否匹配特殊tab,如打印页 :return: tab id组成的列表 """ - if not (by_title or by_url): - return self.tabs - tabs = self._control_session.get(f'http://{self.address}/json').json() # 不要改用cdp - return [i['id'] for i in tabs if i['type'] == 'page' and ((by_url and text in i['url']) or - (by_title and text in i['title']))] + if text is None or not (by_title or by_url): + return [i['id'] for i in tabs if (not special and i['type'] == 'page') + or (special and i['type'] not in ('page', 'iframe'))] + + return [i['id'] for i in tabs if ((not special and i['type'] == 'page') + or (special and i['type'] not in ('page', 'iframe'))) + and ((by_url and text in i['url']) or (by_title and text in i['title']))] def new_tab(self, url=None, switch_to=True): """新建一个标签页,该标签页在最后面 diff --git a/DrissionPage/chromium_page.pyi b/DrissionPage/chromium_page.pyi index f9e271f..30756c9 100644 --- a/DrissionPage/chromium_page.pyi +++ b/DrissionPage/chromium_page.pyi @@ -81,7 +81,8 @@ class ChromiumPage(ChromiumBase): def get_tab(self, tab_id: str = None) -> ChromiumTab: ... - def find_tabs(self, text: str, by_title: bool = True, by_url: bool = None) -> List[str]: ... + def find_tabs(self, text: str = None, by_title: bool = True, by_url: bool = None, + special: bool = False) -> List[str]: ... def new_tab(self, url: str = None, switch_to: bool = True) -> str: ... diff --git a/DrissionPage/chromium_tab.py b/DrissionPage/chromium_tab.py index 5912094..a97c9e7 100644 --- a/DrissionPage/chromium_tab.py +++ b/DrissionPage/chromium_tab.py @@ -28,6 +28,11 @@ class ChromiumTab(ChromiumBase): self.retry_interval = self.page.retry_interval self._page_load_strategy = self.page.page_load_strategy + @property + def rect(self): + """返回获取窗口坐标和大小的对象""" + return self.page.rect + class WebPageTab(SessionPage, ChromiumTab): def __init__(self, page, tab_id): diff --git a/DrissionPage/chromium_tab.pyi b/DrissionPage/chromium_tab.pyi index f9682b2..9def1d7 100644 --- a/DrissionPage/chromium_tab.pyi +++ b/DrissionPage/chromium_tab.pyi @@ -11,7 +11,7 @@ from requests import Session, Response from .chromium_base import ChromiumBase, ChromiumBaseSetter from .chromium_element import ChromiumElement from .chromium_frame import ChromiumFrame -from .chromium_page import ChromiumPage +from .chromium_page import ChromiumPage, ChromiumTabRect from .session_element import SessionElement from .session_page import SessionPage, SessionPageSetter, DownloadSetter from .web_page import WebPage @@ -24,6 +24,9 @@ class ChromiumTab(ChromiumBase): def _set_runtime_settings(self) -> None: ... + @property + def rect(self) -> ChromiumTabRect: ... + class WebPageTab(SessionPage, ChromiumTab): def __init__(self, page: WebPage, tab_id: str): diff --git a/setup.py b/setup.py index 1526a04..dc49e70 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="3.2.25", + version="3.2.26", author="g1879", author_email="g1879@qq.com", description="Python based web automation tool. It can control the browser and send and receive data packets.",