From 514a9da2f4eb71c65fb751607d642b77399c8d98 Mon Sep 17 00:00:00 2001 From: g1879 Date: Sat, 11 May 2024 17:50:36 +0800 Subject: [PATCH] =?UTF-8?q?tree()=E5=8F=AF=E6=98=BE=E7=A4=BA=E6=96=87?= =?UTF-8?q?=E6=9C=AC=EF=BC=9B=E4=BF=AE=E5=A4=8DSessionPage()=E8=AE=BF?= =?UTF-8?q?=E9=97=AE=E6=9C=AC=E5=9C=B0=E4=B8=AD=E6=96=87=E8=B7=AF=E5=BE=84?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98=EF=BC=9Btab=5Fids=E4=B8=8D=E5=86=8D?= =?UTF-8?q?=E5=B1=8F=E8=94=BD=E6=8F=92=E4=BB=B6tab?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DrissionPage/__init__.py | 2 +- DrissionPage/_base/base.py | 3 ++- DrissionPage/_base/browser.py | 2 +- DrissionPage/_functions/web.py | 29 ++++++++++++++++++++++++++--- DrissionPage/_functions/web.pyi | 5 ++++- 5 files changed, 34 insertions(+), 7 deletions(-) diff --git a/DrissionPage/__init__.py b/DrissionPage/__init__.py index 6058306..e0efad4 100644 --- a/DrissionPage/__init__.py +++ b/DrissionPage/__init__.py @@ -14,4 +14,4 @@ from ._configs.chromium_options import ChromiumOptions from ._configs.session_options import SessionOptions __all__ = ['ChromiumPage', 'ChromiumOptions', 'SessionOptions', 'SessionPage', 'WebPage', '__version__'] -__version__ = '4.0.4.22' +__version__ = '4.0.4.23' diff --git a/DrissionPage/_base/base.py b/DrissionPage/_base/base.py index 205baaa..a1e4ce3 100644 --- a/DrissionPage/_base/base.py +++ b/DrissionPage/_base/base.py @@ -411,7 +411,8 @@ class BasePage(BaseParser): if p.exists(): url = str(p.absolute()) 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 interval = interval if interval is not None else self.retry_interval return retry, interval, is_file diff --git a/DrissionPage/_base/browser.py b/DrissionPage/_base/browser.py index 124acc4..00649d5 100644 --- a/DrissionPage/_base/browser.py +++ b/DrissionPage/_base/browser.py @@ -135,7 +135,7 @@ class Browser(object): """返回所有标签页id组成的列表""" j = self._driver.get(f'http://{self.address}/json').json() # 不要改用cdp,因为顺序不对 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 def process_id(self): diff --git a/DrissionPage/_functions/web.py b/DrissionPage/_functions/web.py index a7fd75c..132d418 100644 --- a/DrissionPage/_functions/web.py +++ b/DrissionPage/_functions/web.py @@ -466,9 +466,12 @@ def get_pdf(page, path=None, name=None, kwargs=None): return r -def tree(ele_or_page): +def tree(ele_or_page, text=False, show_js=False, show_css=False): """把页面或元素对象DOM结构打印出来 :param ele_or_page: 页面或元素对象 + :param text: 是否打印文本,输入数字可指定打印文本长度上线 + :param show_js: 打印文本时是否包含