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.",