mirror of
https://gitee.com/g1879/DrissionPage.git
synced 2024-12-10 04:00:23 +08:00
修复页面跳转后立刻获取html报错问题;优化find_tabs()
This commit is contained in:
parent
19c1567fc4
commit
da39d50640
@ -283,7 +283,8 @@ class ChromiumBase(BasePage):
|
|||||||
@property
|
@property
|
||||||
def html(self):
|
def html(self):
|
||||||
"""返回当前页面html文本"""
|
"""返回当前页面html文本"""
|
||||||
return self.run_cdp_loaded('DOM.getOuterHTML', objectId=self._root_id)['outerHTML']
|
self.wait.load_complete()
|
||||||
|
return self.run_cdp('DOM.getOuterHTML', objectId=self._root_id)['outerHTML']
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def json(self):
|
def json(self):
|
||||||
|
@ -194,22 +194,25 @@ class ChromiumPage(ChromiumBase):
|
|||||||
tab_id = tab_id or self.tab_id
|
tab_id = tab_id or self.tab_id
|
||||||
return ChromiumTab(self, tab_id)
|
return ChromiumTab(self, tab_id)
|
||||||
|
|
||||||
def find_tabs(self, text=None, by_title=True, by_url=None, special=False):
|
def find_tabs(self, title=None, url=None, tab_type=None, single=True):
|
||||||
"""查找符合条件的tab,返回它们的id组成的列表
|
"""查找符合条件的tab,返回它们的id组成的列表
|
||||||
:param text: 查询条件
|
:param title: 要匹配title的文本
|
||||||
:param by_title: 是否匹配title
|
:param url: 要匹配url的文本
|
||||||
:param by_url: 是否匹配url
|
:param tab_type: tab类型,可用列表输入多个
|
||||||
:param special: 是否匹配特殊tab,如打印页
|
:param single: 是否返回首个结果的id,为False返回所有信息
|
||||||
:return: tab id组成的列表
|
:return: tab id或tab dict
|
||||||
"""
|
"""
|
||||||
tabs = self._control_session.get(f'http://{self.address}/json').json() # 不要改用cdp
|
tabs = self._control_session.get(f'http://{self.address}/json').json() # 不要改用cdp
|
||||||
if text is None or not (by_title or by_url):
|
if isinstance(tab_type, str):
|
||||||
return [i['id'] for i in tabs if (not special and i['type'] == 'page')
|
tab_type = {tab_type}
|
||||||
or (special and i['type'] not in ('page', 'iframe'))]
|
elif isinstance(tab_type, (list, tuple, set)):
|
||||||
|
tab_type = set(tab_type)
|
||||||
|
elif tab_type is not None:
|
||||||
|
raise TypeError('tab_type只能是set、list、tuple、str、None。')
|
||||||
|
|
||||||
return [i['id'] for i in tabs if ((not special and i['type'] == 'page')
|
r = [i for i in tabs if ((title is None or title in i['title']) and (url is None or url in i['url'])
|
||||||
or (special and i['type'] not in ('page', 'iframe')))
|
and (tab_type is None or i['type'] in tab_type))]
|
||||||
and ((by_url and text in i['url']) or (by_title and text in i['title']))]
|
return r[0]['id'] if r and single else r
|
||||||
|
|
||||||
def new_tab(self, url=None, switch_to=True):
|
def new_tab(self, url=None, switch_to=True):
|
||||||
"""新建一个标签页,该标签页在最后面
|
"""新建一个标签页,该标签页在最后面
|
||||||
|
@ -82,8 +82,8 @@ class ChromiumPage(ChromiumBase):
|
|||||||
|
|
||||||
def get_tab(self, tab_id: str = None) -> ChromiumTab: ...
|
def get_tab(self, tab_id: str = None) -> ChromiumTab: ...
|
||||||
|
|
||||||
def find_tabs(self, text: str = None, by_title: bool = True, by_url: bool = None,
|
def find_tabs(self, title: str = None, url: str = None,
|
||||||
special: bool = False) -> List[str]: ...
|
tab_type: Union[str, list, tuple, set] = None, single: bool = True) -> Union[str, List[str]]: ...
|
||||||
|
|
||||||
def new_tab(self, url: str = None, switch_to: bool = True) -> str: ...
|
def new_tab(self, url: str = None, switch_to: bool = True) -> str: ...
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user