From 0d9951f51678d967213b100feb2dd6e65c26af30 Mon Sep 17 00:00:00 2001 From: g1879 Date: Sun, 1 Dec 2024 22:37:38 +0800 Subject: [PATCH] =?UTF-8?q?ChromiumFrame=E8=A1=A5=E5=85=85style()=EF=BC=9B?= =?UTF-8?q?DownloadKit=E6=8C=87=E5=AE=9A2.0.7=E6=88=96=E4=BB=A5=E4=B8=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DrissionPage/_pages/chromium_base.py | 7 +++++-- DrissionPage/_pages/chromium_frame.py | 3 +++ DrissionPage/_pages/chromium_frame.pyi | 8 ++++++++ requirements.txt | 2 +- setup.py | 2 +- 5 files changed, 18 insertions(+), 4 deletions(-) diff --git a/DrissionPage/_pages/chromium_base.py b/DrissionPage/_pages/chromium_base.py index cf807be..ab332bd 100644 --- a/DrissionPage/_pages/chromium_base.py +++ b/DrissionPage/_pages/chromium_base.py @@ -33,7 +33,7 @@ from .._units.scroller import PageScroller from .._units.setter import ChromiumBaseSetter from .._units.states import PageStates from .._units.waiter import BaseWaiter -from ..errors import ContextLostError, CDPError, PageDisconnectedError, ElementLostError +from ..errors import ContextLostError, CDPError, PageDisconnectedError, ElementLostError, JavaScriptError __ERROR__ = 'error' @@ -600,7 +600,10 @@ class ChromiumBase(BasePage): else: raise TypeError('html_or_info参数必须是html文本或tuple,tuple格式为(tag, {name: value})。') - ele = self._run_js(js, *args) + try: + ele = self._run_js(js, *args) + except JavaScriptError: + raise RuntimeError('此网页DOM不允许修改。') return ele def get_frame(self, loc_ind_ele, timeout=None): diff --git a/DrissionPage/_pages/chromium_frame.py b/DrissionPage/_pages/chromium_frame.py index 2e7a243..8b02be3 100644 --- a/DrissionPage/_pages/chromium_frame.py +++ b/DrissionPage/_pages/chromium_frame.py @@ -333,6 +333,9 @@ class ChromiumFrame(ChromiumBase): def remove_attr(self, name): self.frame_ele.remove_attr(name) + def style(self, style, pseudo_ele=''): + return self.frame_ele.style(style=style, pseudo_ele=pseudo_ele) + def run_js(self, script, *args, as_expr=False, timeout=None): return self._run_js(script, *args, as_expr=as_expr, timeout=timeout) diff --git a/DrissionPage/_pages/chromium_frame.pyi b/DrissionPage/_pages/chromium_frame.pyi index 19c695d..66758a5 100644 --- a/DrissionPage/_pages/chromium_frame.pyi +++ b/DrissionPage/_pages/chromium_frame.pyi @@ -240,6 +240,14 @@ class ChromiumFrame(ChromiumBase): """ ... + def style(self, style: str, pseudo_ele: str = '') -> str: + """返回frame元素样式属性值,可获取伪元素属性值 + :param style: 样式属性名称 + :param pseudo_ele: 伪元素名称(如有) + :return: 样式属性的值 + """ + ... + def run_js(self, script: str, *args, diff --git a/requirements.txt b/requirements.txt index 3713b42..1e8ab6b 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,7 +1,7 @@ requests lxml cssselect -DownloadKit>=2.0.5 +DownloadKit>=2.0.7 websocket-client click tldextract>=3.4.4 diff --git a/setup.py b/setup.py index 5e7b984..f1c9baf 100644 --- a/setup.py +++ b/setup.py @@ -23,7 +23,7 @@ setup( 'lxml', 'requests', 'cssselect', - 'DownloadKit>=2.0.5', + 'DownloadKit>=2.0.7', 'websocket-client', 'click', 'tldextract>=3.4.4',