mirror of
https://gitee.com/g1879/DrissionPage.git
synced 2024-12-10 04:00:23 +08:00
3.0.23改进ChromiumFrame
This commit is contained in:
parent
b1d9666fd8
commit
4a812d2793
@ -20,14 +20,17 @@ class ChromiumFrame(ChromiumBase):
|
|||||||
|
|
||||||
if self._is_inner_frame():
|
if self._is_inner_frame():
|
||||||
self._is_diff_domain = False
|
self._is_diff_domain = False
|
||||||
super().__init__(page.address, page.tab_id, page.timeout)
|
|
||||||
self.doc_ele = ChromiumElement(self.page, backend_id=node['contentDocument']['backendNodeId'])
|
self.doc_ele = ChromiumElement(self.page, backend_id=node['contentDocument']['backendNodeId'])
|
||||||
|
super().__init__(page.address, page.tab_id, page.timeout)
|
||||||
else:
|
else:
|
||||||
self._is_diff_domain = True
|
self._is_diff_domain = True
|
||||||
super().__init__(page.address, self.frame_id, page.timeout)
|
super().__init__(page.address, self.frame_id, page.timeout)
|
||||||
obj_id = super().run_script('document;', as_expr=True)['objectId']
|
obj_id = super().run_script('document;', as_expr=True)['objectId']
|
||||||
self.doc_ele = ChromiumElement(self, obj_id=obj_id)
|
self.doc_ele = ChromiumElement(self, obj_id=obj_id)
|
||||||
|
|
||||||
|
self._tab_obj.Page.FrameAttached = self._onFrameAttached
|
||||||
|
self._tab_obj.Page.FrameDetached = self._onFrameDetached
|
||||||
|
|
||||||
def __call__(self, loc_or_str, timeout=None):
|
def __call__(self, loc_or_str, timeout=None):
|
||||||
"""在内部查找元素 \n
|
"""在内部查找元素 \n
|
||||||
例:ele2 = ele1('@id=ele_id') \n
|
例:ele2 = ele1('@id=ele_id') \n
|
||||||
@ -53,8 +56,8 @@ class ChromiumFrame(ChromiumBase):
|
|||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
if self._is_inner_frame():
|
if self._is_inner_frame():
|
||||||
node = self.page.run_cdp('DOM.describeNode', backendNodeId=self.backend_id, not_change=True)[
|
node = self.page.run_cdp('DOM.describeNode',
|
||||||
'node']
|
backendNodeId=self.backend_id, not_change=True)['node']
|
||||||
self.doc_ele = ChromiumElement(self.page, backend_id=node['contentDocument']['backendNodeId'])
|
self.doc_ele = ChromiumElement(self.page, backend_id=node['contentDocument']['backendNodeId'])
|
||||||
else:
|
else:
|
||||||
b_id = self._tab_obj.DOM.getDocument()['root']['backendNodeId']
|
b_id = self._tab_obj.DOM.getDocument()['root']['backendNodeId']
|
||||||
@ -88,6 +91,14 @@ class ChromiumFrame(ChromiumBase):
|
|||||||
print('页面停止加载 FrameStoppedLoading')
|
print('页面停止加载 FrameStoppedLoading')
|
||||||
self._get_new_document()
|
self._get_new_document()
|
||||||
|
|
||||||
|
def _onFrameAttached(self, **kwargs):
|
||||||
|
if self._debug:
|
||||||
|
print(f'FrameAttached{[kwargs]}')
|
||||||
|
|
||||||
|
def _onFrameDetached(self, **kwargs):
|
||||||
|
if self._debug:
|
||||||
|
print(f'FrameDetached{[kwargs]}')
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def tab_id(self):
|
def tab_id(self):
|
||||||
"""返回当前标签页id"""
|
"""返回当前标签页id"""
|
||||||
@ -189,6 +200,14 @@ class ChromiumFrame(ChromiumBase):
|
|||||||
"""返回frame的css selector绝对路径"""
|
"""返回frame的css selector绝对路径"""
|
||||||
return self.frame_ele.css_path
|
return self.frame_ele.css_path
|
||||||
|
|
||||||
|
@property
|
||||||
|
def ready_state(self):
|
||||||
|
"""返回当前页面加载状态,'loading' 'interactive' 'complete'"""
|
||||||
|
if self._is_diff_domain:
|
||||||
|
return super().ready_state
|
||||||
|
else:
|
||||||
|
return self.doc_ele.run_script('return this.readyState;')
|
||||||
|
|
||||||
def refresh(self):
|
def refresh(self):
|
||||||
"""刷新frame页面"""
|
"""刷新frame页面"""
|
||||||
self.doc_ele.run_script('this.location.reload();')
|
self.doc_ele.run_script('this.location.reload();')
|
||||||
|
@ -5,7 +5,6 @@
|
|||||||
"""
|
"""
|
||||||
from typing import Union, Tuple, List, Any
|
from typing import Union, Tuple, List, Any
|
||||||
|
|
||||||
from session_element import SessionElement
|
|
||||||
from .chromium_element import ChromiumElement
|
from .chromium_element import ChromiumElement
|
||||||
from .chromium_base import ChromiumBase
|
from .chromium_base import ChromiumBase
|
||||||
|
|
||||||
@ -32,7 +31,22 @@ class ChromiumFrame(ChromiumBase):
|
|||||||
|
|
||||||
def __repr__(self) -> str: ...
|
def __repr__(self) -> str: ...
|
||||||
|
|
||||||
def _is_inner_frame(self) -> bool: ...
|
def _get_new_document(self) -> None: ...
|
||||||
|
|
||||||
|
@property
|
||||||
|
def tab_id(self) -> str: ...
|
||||||
|
|
||||||
|
@property
|
||||||
|
def backend_id(self) -> str: ...
|
||||||
|
|
||||||
|
@property
|
||||||
|
def obj_id(self) -> str: ...
|
||||||
|
|
||||||
|
@property
|
||||||
|
def node_id(self) -> str: ...
|
||||||
|
|
||||||
|
@property
|
||||||
|
def frame_ele(self) -> ChromiumElement: ...
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def tag(self) -> str: ...
|
def tag(self) -> str: ...
|
||||||
@ -43,15 +57,15 @@ class ChromiumFrame(ChromiumBase):
|
|||||||
@property
|
@property
|
||||||
def html(self) -> str: ...
|
def html(self) -> str: ...
|
||||||
|
|
||||||
|
@property
|
||||||
|
def inner_html(self) -> str: ...
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def title(self) -> str: ...
|
def title(self) -> str: ...
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def cookies(self) -> dict: ...
|
def cookies(self) -> dict: ...
|
||||||
|
|
||||||
@property
|
|
||||||
def inner_html(self) -> str: ...
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def attrs(self) -> dict: ...
|
def attrs(self) -> dict: ...
|
||||||
|
|
||||||
@ -64,18 +78,6 @@ class ChromiumFrame(ChromiumBase):
|
|||||||
@property
|
@property
|
||||||
def active_ele(self) -> ChromiumElement: ...
|
def active_ele(self) -> ChromiumElement: ...
|
||||||
|
|
||||||
@property
|
|
||||||
def obj_id(self) -> str: ...
|
|
||||||
|
|
||||||
@property
|
|
||||||
def node_id(self) -> str: ...
|
|
||||||
|
|
||||||
@property
|
|
||||||
def backend_id(self) -> str: ...
|
|
||||||
|
|
||||||
@property
|
|
||||||
def frame_ele(self) -> ChromiumElement: ...
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def location(self) -> dict: ...
|
def location(self) -> dict: ...
|
||||||
|
|
||||||
@ -88,32 +90,8 @@ class ChromiumFrame(ChromiumBase):
|
|||||||
@property
|
@property
|
||||||
def css_path(self) -> str: ...
|
def css_path(self) -> str: ...
|
||||||
|
|
||||||
def get(self,
|
|
||||||
url: str,
|
|
||||||
show_errmsg: bool = ...,
|
|
||||||
retry: int = ...,
|
|
||||||
interval: float = ...,
|
|
||||||
timeout: float = ...) -> Union[None, bool]: ...
|
|
||||||
|
|
||||||
def refresh(self) -> None: ...
|
def refresh(self) -> None: ...
|
||||||
|
|
||||||
def forward(self, steps: int = ...) -> None: ...
|
|
||||||
|
|
||||||
def back(self, steps: int = ...) -> None: ...
|
|
||||||
|
|
||||||
def ele(self,
|
|
||||||
loc_or_ele: Union[Tuple[str, str], str, ChromiumElement, 'ChromiumFrame'],
|
|
||||||
timeout: float = ...): ...
|
|
||||||
|
|
||||||
def eles(self,
|
|
||||||
loc_or_str: Union[Tuple[str, str], str],
|
|
||||||
timeout: float = ...): ...
|
|
||||||
|
|
||||||
def s_ele(self, loc_or_str: Union[Tuple[str, str], str, ChromiumElement] = ...) -> Union[
|
|
||||||
SessionElement, str, None]: ...
|
|
||||||
|
|
||||||
def s_eles(self, loc_or_str: Union[Tuple[str, str], str] = ...) -> List[Union[SessionElement, str]]: ...
|
|
||||||
|
|
||||||
def attr(self, attr: str) -> Union[str, None]: ...
|
def attr(self, attr: str) -> Union[str, None]: ...
|
||||||
|
|
||||||
def set_attr(self, attr: str, value: str) -> None: ...
|
def set_attr(self, attr: str, value: str) -> None: ...
|
||||||
@ -155,3 +133,17 @@ class ChromiumFrame(ChromiumBase):
|
|||||||
def befores(self,
|
def befores(self,
|
||||||
filter_loc: Union[tuple, str] = ...,
|
filter_loc: Union[tuple, str] = ...,
|
||||||
timeout: float = ...) -> List[Union[ChromiumElement, ChromiumFrame, str]]: ...
|
timeout: float = ...) -> List[Union[ChromiumElement, ChromiumFrame, str]]: ...
|
||||||
|
|
||||||
|
def _ele(self,
|
||||||
|
loc_or_ele: Union[Tuple[str, str], str, ChromiumElement, ChromiumFrame],
|
||||||
|
timeout: float = ..., single: bool = ..., relative: bool = ...) \
|
||||||
|
-> Union[ChromiumElement, ChromiumFrame, None, List[Union[ChromiumElement, ChromiumFrame]]]: ...
|
||||||
|
|
||||||
|
def _d_connect(self,
|
||||||
|
to_url: str,
|
||||||
|
times: int = ...,
|
||||||
|
interval: float = ...,
|
||||||
|
show_errmsg: bool = ...,
|
||||||
|
timeout: float = ...) -> Union[bool, None]: ...
|
||||||
|
|
||||||
|
def _is_inner_frame(self) -> bool: ...
|
||||||
|
12
docs/版本历史.md
12
docs/版本历史.md
@ -1,3 +1,15 @@
|
|||||||
|
# v3.0.23
|
||||||
|
|
||||||
|
- 各种大小、位置信息从`dict`改为用`tuple`返回
|
||||||
|
|
||||||
|
- 改进`ChromiumFrame`
|
||||||
|
|
||||||
|
- 修复小窗时定位不准问题,修复 iframe 内元素无法获取 s_ele() 问题
|
||||||
|
|
||||||
|
- 增加`wait_loading`方法和参数
|
||||||
|
|
||||||
|
- 其它优化
|
||||||
|
|
||||||
# v3.0.22
|
# v3.0.22
|
||||||
|
|
||||||
- `change_mode()`增加`copy_cookies`参数
|
- `change_mode()`增加`copy_cookies`参数
|
||||||
|
Loading…
x
Reference in New Issue
Block a user