From d1b4a23bed42a436ce71f2337bdbcf4eca438927 Mon Sep 17 00:00:00 2001 From: g1879 Date: Mon, 19 Aug 2024 00:24:26 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=BC=AA=E5=85=83=E7=B4=A0?= =?UTF-8?q?=E6=96=87=E6=9C=AC=E6=9C=89=E6=97=B6=E8=8E=B7=E5=8F=96=E4=B8=8D?= =?UTF-8?q?=E6=AD=A3=E7=A1=AE=E7=9A=84=E9=97=AE=E9=A2=98=EF=BC=9BChromiumF?= =?UTF-8?q?rame=E5=A2=9E=E5=8A=A0link=E5=B1=9E=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DrissionPage/_base/browser.py | 3 +-- DrissionPage/_base/browser.pyi | 14 +++++++------- DrissionPage/_elements/chromium_element.py | 14 +++++++++++--- DrissionPage/_elements/chromium_element.pyi | 4 ++-- DrissionPage/_functions/browser.py | 2 +- DrissionPage/_pages/chromium_frame.py | 4 ++++ DrissionPage/_pages/chromium_frame.pyi | 7 ++++++- DrissionPage/_pages/tabs.py | 3 ++- 8 files changed, 34 insertions(+), 17 deletions(-) diff --git a/DrissionPage/_base/browser.py b/DrissionPage/_base/browser.py index ce65d36..d13a833 100644 --- a/DrissionPage/_base/browser.py +++ b/DrissionPage/_base/browser.py @@ -15,7 +15,6 @@ from websocket import WebSocketBadStatusException from .driver import BrowserDriver, Driver from .._configs.chromium_options import ChromiumOptions -from .._configs.session_options import SessionOptions from .._functions.browser import connect_browser from .._functions.cookies import CookiesList from .._functions.settings import Settings @@ -106,7 +105,7 @@ class Chromium(object): self._driver.set_callback('Target.targetCreated', self._onTargetCreated) self._dl_mgr = DownloadManager(self) - self._session_options = SessionOptions() if session_options is True else session_options + self._session_options = session_options @property def user_data_path(self): diff --git a/DrissionPage/_base/browser.pyi b/DrissionPage/_base/browser.pyi index 33f8423..59a211a 100644 --- a/DrissionPage/_base/browser.pyi +++ b/DrissionPage/_base/browser.pyi @@ -20,13 +20,15 @@ from .._units.waiter import BrowserWaiter class Chromium(object): + _BROWSERS: dict = ... + _lock: Lock = ... + id: str = ... address: str = ... version: str = ... retry_times: int = ... retry_interval: float = ... - _BROWSERS: dict = ... _chromium_options: ChromiumOptions = ... _session_options: SessionOptions = ... _driver: BrowserDriver = ... @@ -35,8 +37,6 @@ class Chromium(object): _all_drivers: Dict[str, Set[Driver]] = ... _process_id: Optional[int] = ... _dl_mgr: DownloadManager = ... - _lock: Lock = ... - _set: Optional[BrowserSetter] = ... _wait: Optional[BrowserWaiter] = ... _timeouts: Timeout = ... @@ -47,18 +47,18 @@ class Chromium(object): def __new__(cls, addr_or_opts: Union[str, int, ChromiumOptions] = None, - session_options: Optional[SessionOptions] = None): + session_options: Union[SessionOptions, None, False] = None): """ :param addr_or_opts: 浏览器地址:端口、ChromiumOptions对象或端口数字(int) - :param session_options: 使用双模Tab时使用的默认Session配置,为True使用ini文件配置 + :param session_options: 使用双模Tab时使用的默认Session配置,为None使用ini文件配置,为False不从ini读取 """ ... def __init__(self, addr_or_opts: Union[str, int, ChromiumOptions] = None, - session_options: Optional[SessionOptions] = None): + session_options: Union[SessionOptions, None, False] = None): """ :param addr_or_opts: 浏览器地址:端口、ChromiumOptions对象或端口数字(int) - :param session_options: 使用双模Tab时使用的默认Session配置,为True使用ini文件配置 + :param session_options: 使用双模Tab时使用的默认Session配置,为None使用ini文件配置,为False不从ini读取 """ ... diff --git a/DrissionPage/_elements/chromium_element.py b/DrissionPage/_elements/chromium_element.py index c63fa67..6706eb6 100644 --- a/DrissionPage/_elements/chromium_element.py +++ b/DrissionPage/_elements/chromium_element.py @@ -433,7 +433,7 @@ class ChromiumElement(DrissionElement): def style(self, style, pseudo_ele=''): if pseudo_ele: - pseudo_ele = f', "{pseudo_ele}"' if pseudo_ele.startswith(':') else f', "::{pseudo_ele}"' + pseudo_ele = f', "{pseudo_ele}"' return self._run_js(f'return window.getComputedStyle(this{pseudo_ele}).getPropertyValue("{style}");') def src(self, timeout=None, base64_to_bytes=True): @@ -1297,11 +1297,19 @@ class Pseudo(object): @property def before(self): - return self._ele.style('content', 'before') + for i in ('::before', ':before', 'before'): + r = self._ele.style('content', i) + if r != 'content': + return r + return r @property def after(self): - return self._ele.style('content', 'after') + for i in ('::after', ':after', 'after'): + r = self._ele.style('content', i) + if r != 'content': + return r + return r def _check_ele(ele, loc_data): diff --git a/DrissionPage/_elements/chromium_element.pyi b/DrissionPage/_elements/chromium_element.pyi index 181ef05..f1b4290 100644 --- a/DrissionPage/_elements/chromium_element.pyi +++ b/DrissionPage/_elements/chromium_element.pyi @@ -965,10 +965,10 @@ class Pseudo(object): @property def before(self) -> str: - """返回当前元素的::before伪元素内容""" + """返回当前元素的::before伪元素文本内容""" ... @property def after(self) -> str: - """返回当前元素的::after伪元素内容""" + """返回当前元素的::after伪元素文本内容""" ... diff --git a/DrissionPage/_functions/browser.py b/DrissionPage/_functions/browser.py index 250db6a..9f8bcd3 100644 --- a/DrissionPage/_functions/browser.py +++ b/DrissionPage/_functions/browser.py @@ -21,7 +21,7 @@ from ..errors import BrowserConnectError def connect_browser(option): - address = option.address.replace('localhost', '127.0.0.1').lstrip('http://').lstrip('https://') + address = option.address.replace('localhost', '127.0.0.1').lstrip('htps:/') browser_path = option.browser_path ip, port = address.split(':') diff --git a/DrissionPage/_pages/chromium_frame.py b/DrissionPage/_pages/chromium_frame.py index dec139d..fc2ecc6 100644 --- a/DrissionPage/_pages/chromium_frame.py +++ b/DrissionPage/_pages/chromium_frame.py @@ -259,6 +259,10 @@ class ChromiumFrame(ChromiumBase): def inner_html(self): return self.doc_ele._run_js('return this.documentElement.outerHTML;') + @property + def link(self): + return self.frame_ele.link + @property def title(self): r = self._ele('t:title', raise_err=False) diff --git a/DrissionPage/_pages/chromium_frame.pyi b/DrissionPage/_pages/chromium_frame.pyi index 46cc119..bbb7c93 100644 --- a/DrissionPage/_pages/chromium_frame.pyi +++ b/DrissionPage/_pages/chromium_frame.pyi @@ -154,6 +154,11 @@ class ChromiumFrame(ChromiumBase): """返回元素innerHTML文本""" ... + @property + def link(self) -> str: + """返回href或src绝对url""" + ... + @property def title(self) -> str: """返回页面title""" @@ -205,7 +210,7 @@ class ChromiumFrame(ChromiumBase): ... @property - def _js_ready_state(self)->Literal['loading', 'interactive', 'complete']: + def _js_ready_state(self) -> Literal['loading', 'interactive', 'complete']: """返回当前页面加载状态""" ... diff --git a/DrissionPage/_pages/tabs.py b/DrissionPage/_pages/tabs.py index 3ab4044..1470895 100644 --- a/DrissionPage/_pages/tabs.py +++ b/DrissionPage/_pages/tabs.py @@ -82,7 +82,8 @@ class MixTab(SessionPage, ChromiumTab, BasePage): self._mode = 'd' self._has_driver = True self._has_session = True - super().__init__(session_or_options=browser._session_options if browser._session_options else SessionOptions()) + super().__init__(session_or_options=browser._session_options or SessionOptions( + read_file=browser._session_options is None)) super(SessionPage, self).__init__(browser=browser, tab_id=tab_id) self._type = 'MixTab'