mirror of
https://gitee.com/g1879/DrissionPage.git
synced 2024-12-10 04:00:23 +08:00
元素对象间可用==判断是否指向同一个元素;Page的save()默认返回文本不保存
This commit is contained in:
parent
6f5020f955
commit
34c5ad818b
@ -85,6 +85,9 @@ class ChromiumElement(DrissionElement):
|
||||
"""
|
||||
return self.ele(loc_or_str, timeout)
|
||||
|
||||
def __eq__(self, other):
|
||||
return self._backend_id == getattr(other, '_backend_id', None)
|
||||
|
||||
@property
|
||||
def tag(self):
|
||||
"""返回元素tag"""
|
||||
@ -794,6 +797,9 @@ class ShadowRoot(BaseElement):
|
||||
"""
|
||||
return self.ele(loc_or_str, timeout)
|
||||
|
||||
def __eq__(self, other):
|
||||
return self._backend_id == getattr(other, '_backend_id', None)
|
||||
|
||||
@property
|
||||
def tag(self):
|
||||
"""返回元素标签名"""
|
||||
|
@ -48,6 +48,8 @@ class ChromiumElement(DrissionElement):
|
||||
def __call__(self, loc_or_str: Union[Tuple[str, str], str],
|
||||
timeout: float = None) -> Union[ChromiumElement, NoneElement]: ...
|
||||
|
||||
def __eq__(self, other: ChromiumElement) -> bool: ...
|
||||
|
||||
@property
|
||||
def tag(self) -> str: ...
|
||||
|
||||
@ -242,6 +244,8 @@ class ShadowRoot(BaseElement):
|
||||
def __call__(self, loc_or_str: Union[Tuple[str, str], str],
|
||||
timeout: float = None) -> ChromiumElement: ...
|
||||
|
||||
def __eq__(self, other: ShadowRoot) -> bool: ...
|
||||
|
||||
@property
|
||||
def states(self) -> ShadowRootStates: ...
|
||||
|
||||
|
@ -43,6 +43,9 @@ class SessionElement(DrissionElement):
|
||||
"""
|
||||
return self.ele(loc_or_str)
|
||||
|
||||
def __eq__(self, other):
|
||||
return self.xpath == getattr(other, 'xpath', None)
|
||||
|
||||
@property
|
||||
def tag(self):
|
||||
"""返回元素类型"""
|
||||
|
@ -30,6 +30,8 @@ class SessionElement(DrissionElement):
|
||||
loc_or_str: Union[Tuple[str, str], str],
|
||||
timeout: float = None) -> Union[SessionElement, NoneElement]: ...
|
||||
|
||||
def __eq__(self, other: SessionElement) -> bool: ...
|
||||
|
||||
@property
|
||||
def tag(self) -> str: ...
|
||||
|
||||
|
@ -1153,13 +1153,15 @@ def close_privacy_dialog(page, tid):
|
||||
|
||||
|
||||
def get_mhtml(page, path=None, name=None):
|
||||
"""把当前页面保存为mhtml文件
|
||||
"""把当前页面保存为mhtml文件,如果path和name参数都为None,只返回mhtml文本
|
||||
:param page: 要保存的页面对象
|
||||
:param path: 保存路径,为None保存在当前路径
|
||||
:param name: 文件名,为None则用title属性值
|
||||
:param path: 保存路径,为None且name不为None时保存在当前路径
|
||||
:param name: 文件名,为None且path不为None时用title属性值
|
||||
:return: mhtml文本
|
||||
"""
|
||||
r = page.run_cdp('Page.captureSnapshot')['data']
|
||||
if path is None and name is None:
|
||||
return r
|
||||
path = path or '.'
|
||||
Path(path).mkdir(parents=True, exist_ok=True)
|
||||
name = make_valid_name(name or page.title)
|
||||
|
@ -71,6 +71,9 @@ class ChromiumFrame(ChromiumBase):
|
||||
"""
|
||||
return self.ele(loc_or_str, timeout)
|
||||
|
||||
def __eq__(self, other):
|
||||
return self._frame_id == getattr(other, '_frame_id', None)
|
||||
|
||||
def __repr__(self):
|
||||
attrs = self._frame_ele.attrs
|
||||
attrs = [f"{attr}='{attrs[attr]}'" for attr in attrs]
|
||||
|
@ -44,6 +44,8 @@ class ChromiumFrame(ChromiumBase):
|
||||
loc_or_str: Union[Tuple[str, str], str],
|
||||
timeout: float = None) -> Union[ChromiumElement, NoneElement]: ...
|
||||
|
||||
def __eq__(self, other: ChromiumFrame) -> bool: ...
|
||||
|
||||
def _check_alive(self) -> None: ...
|
||||
|
||||
def __repr__(self) -> str: ...
|
||||
|
@ -142,9 +142,9 @@ class ChromiumPage(ChromiumBase):
|
||||
return self.browser.process_id
|
||||
|
||||
def save(self, path=None, name=None):
|
||||
"""把当前页面保存为mhtml文件
|
||||
:param path: 保存路径,为None保存在当前路径
|
||||
:param name: 文件名,为None则用title属性值
|
||||
"""把当前页面保存为mhtml文件,如果path和name参数都为None,只返回mhtml文本
|
||||
:param path: 保存路径,为None且name不为None时保存在当前路径
|
||||
:param name: 文件名,为None且path不为None时用title属性值
|
||||
:return: mhtml文本
|
||||
"""
|
||||
return get_mhtml(self, path, name)
|
||||
|
@ -59,9 +59,9 @@ class ChromiumTab(ChromiumBase):
|
||||
return self._wait
|
||||
|
||||
def save(self, path=None, name=None):
|
||||
"""把当前页面保存为mhtml文件
|
||||
:param path: 保存路径,为None保存在当前路径
|
||||
:param name: 文件名,为None则用title属性值
|
||||
"""把当前页面保存为mhtml文件,如果path和name参数都为None,只返回mhtml文本
|
||||
:param path: 保存路径,为None且name不为None时保存在当前路径
|
||||
:param name: 文件名,为None且path不为None时用title属性值
|
||||
:return: mhtml文本
|
||||
"""
|
||||
return get_mhtml(self, path, name)
|
||||
|
Loading…
x
Reference in New Issue
Block a user