mirror of
https://gitee.com/g1879/DrissionPage.git
synced 2024-12-10 04:00:23 +08:00
修复伪元素文本有时获取不正确的问题;ChromiumFrame增加link属性
This commit is contained in:
parent
f68dd8e743
commit
d1b4a23bed
@ -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):
|
||||
|
@ -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读取
|
||||
"""
|
||||
...
|
||||
|
||||
|
@ -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):
|
||||
|
@ -965,10 +965,10 @@ class Pseudo(object):
|
||||
|
||||
@property
|
||||
def before(self) -> str:
|
||||
"""返回当前元素的::before伪元素内容"""
|
||||
"""返回当前元素的::before伪元素文本内容"""
|
||||
...
|
||||
|
||||
@property
|
||||
def after(self) -> str:
|
||||
"""返回当前元素的::after伪元素内容"""
|
||||
"""返回当前元素的::after伪元素文本内容"""
|
||||
...
|
||||
|
@ -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(':')
|
||||
|
@ -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)
|
||||
|
@ -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']:
|
||||
"""返回当前页面加载状态"""
|
||||
...
|
||||
|
||||
|
@ -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'
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user