mirror of
https://gitee.com/g1879/DrissionPage.git
synced 2024-12-10 04:00:23 +08:00
tree()可显示文本;修复SessionPage()访问本地中文路径的问题;tab_ids不再屏蔽插件tab
This commit is contained in:
parent
c14a3af41b
commit
514a9da2f4
@ -14,4 +14,4 @@ from ._configs.chromium_options import ChromiumOptions
|
|||||||
from ._configs.session_options import SessionOptions
|
from ._configs.session_options import SessionOptions
|
||||||
|
|
||||||
__all__ = ['ChromiumPage', 'ChromiumOptions', 'SessionOptions', 'SessionPage', 'WebPage', '__version__']
|
__all__ = ['ChromiumPage', 'ChromiumOptions', 'SessionOptions', 'SessionPage', 'WebPage', '__version__']
|
||||||
__version__ = '4.0.4.22'
|
__version__ = '4.0.4.23'
|
||||||
|
@ -411,7 +411,8 @@ class BasePage(BaseParser):
|
|||||||
if p.exists():
|
if p.exists():
|
||||||
url = str(p.absolute())
|
url = str(p.absolute())
|
||||||
is_file = True
|
is_file = True
|
||||||
self._url = quote(url, safe='-_.~!*\'"();:@&=+$,/\\?#[]%')
|
|
||||||
|
self._url = url if is_file else quote(url, safe='-_.~!*\'"();:@&=+$,/\\?#[]%')
|
||||||
retry = retry if retry is not None else self.retry_times
|
retry = retry if retry is not None else self.retry_times
|
||||||
interval = interval if interval is not None else self.retry_interval
|
interval = interval if interval is not None else self.retry_interval
|
||||||
return retry, interval, is_file
|
return retry, interval, is_file
|
||||||
|
@ -135,7 +135,7 @@ class Browser(object):
|
|||||||
"""返回所有标签页id组成的列表"""
|
"""返回所有标签页id组成的列表"""
|
||||||
j = self._driver.get(f'http://{self.address}/json').json() # 不要改用cdp,因为顺序不对
|
j = self._driver.get(f'http://{self.address}/json').json() # 不要改用cdp,因为顺序不对
|
||||||
return [i['id'] for i in j if i['type'] in ('page', 'webview')
|
return [i['id'] for i in j if i['type'] in ('page', 'webview')
|
||||||
and not i['url'].startswith(('devtools://', 'chrome-extension://'))]
|
and not i['url'].startswith('devtools://')]
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def process_id(self):
|
def process_id(self):
|
||||||
|
@ -466,9 +466,12 @@ def get_pdf(page, path=None, name=None, kwargs=None):
|
|||||||
return r
|
return r
|
||||||
|
|
||||||
|
|
||||||
def tree(ele_or_page):
|
def tree(ele_or_page, text=False, show_js=False, show_css=False):
|
||||||
"""把页面或元素对象DOM结构打印出来
|
"""把页面或元素对象DOM结构打印出来
|
||||||
:param ele_or_page: 页面或元素对象
|
:param ele_or_page: 页面或元素对象
|
||||||
|
:param text: 是否打印文本,输入数字可指定打印文本长度上线
|
||||||
|
:param show_js: 打印文本时是否包含<script>内文本,text参数为False时无效
|
||||||
|
:param show_css: 打印文本时是否包含<style>内文本,text参数为False时无效
|
||||||
:return: None
|
:return: None
|
||||||
"""
|
"""
|
||||||
|
|
||||||
@ -488,13 +491,33 @@ def tree(ele_or_page):
|
|||||||
e = list_ele[i]
|
e = list_ele[i]
|
||||||
|
|
||||||
attrs = ' '.join([f"{k}='{v}'" for k, v in e.attrs.items()])
|
attrs = ' '.join([f"{k}='{v}'" for k, v in e.attrs.items()])
|
||||||
print(f'{new_body}{tail}<{e.tag} {attrs}>'.replace('\n', ' '))
|
show_text = f'{new_body}{tail}<{e.tag} {attrs}>'.replace('\n', ' ')
|
||||||
|
if text:
|
||||||
|
t = e('x:/text()')
|
||||||
|
if t:
|
||||||
|
t = t.replace('\n', ' ')
|
||||||
|
if (e.tag not in ('script', 'style') or (e.tag == 'script' and show_js)
|
||||||
|
or (e.tag == 'style' and show_css)):
|
||||||
|
if text is not True:
|
||||||
|
t = t[:text]
|
||||||
|
show_text = f'{show_text} {t}'
|
||||||
|
print(show_text)
|
||||||
|
|
||||||
_tree(e, new_last_one, new_body)
|
_tree(e, new_last_one, new_body)
|
||||||
|
|
||||||
ele = ele_or_page.s_ele()
|
ele = ele_or_page.s_ele()
|
||||||
attrs = ' '.join([f"{k}='{v}'" for k, v in ele.attrs.items()])
|
attrs = ' '.join([f"{k}='{v}'" for k, v in ele.attrs.items()])
|
||||||
print(f'<{ele.tag} {attrs}>'.replace('\n', ' '))
|
show_text = f'<{ele.tag} {attrs}>'.replace('\n', ' ')
|
||||||
|
if text:
|
||||||
|
t = ele('x:/text()')
|
||||||
|
if t:
|
||||||
|
t = t.replace('\n', ' ')
|
||||||
|
if (ele.tag not in ('script', 'style') or (ele.tag == 'script' and show_js)
|
||||||
|
or (ele.tag == 'style' and show_css)):
|
||||||
|
if text is not True:
|
||||||
|
t = t[:text]
|
||||||
|
show_text = f'{show_text} {t}'
|
||||||
|
print(show_text)
|
||||||
_tree(ele)
|
_tree(ele)
|
||||||
|
|
||||||
|
|
||||||
|
@ -73,7 +73,10 @@ def get_pdf(page: Union[ChromiumPage, ChromiumTab],
|
|||||||
kwargs: dict = None) -> Union[bytes, str]: ...
|
kwargs: dict = None) -> Union[bytes, str]: ...
|
||||||
|
|
||||||
|
|
||||||
def tree(ele_or_page: BaseParser) -> None: ...
|
def tree(ele_or_page: BaseParser,
|
||||||
|
text: Union[int, bool] = False,
|
||||||
|
show_js: bool = False,
|
||||||
|
show_css: bool = False) -> None: ...
|
||||||
|
|
||||||
|
|
||||||
def format_headers(txt: str) -> dict: ...
|
def format_headers(txt: str) -> dict: ...
|
||||||
|
Loading…
x
Reference in New Issue
Block a user