微调,未完成

This commit is contained in:
g1879 2022-12-22 22:29:23 +08:00
parent 59f4adb1b2
commit 0713ebddfa
2 changed files with 10 additions and 4 deletions

View File

@ -25,7 +25,7 @@ class ChromiumFrame(object):
node = page.run_cdp('DOM.describeNode', nodeId=ele.node_id, not_change=True)['node'] node = page.run_cdp('DOM.describeNode', nodeId=ele.node_id, not_change=True)['node']
self.frame_id = node.get('frameId', None) self.frame_id = node.get('frameId', None)
if self.frame_id in str(self.page.run_cdp('Page.getFrameTree', not_change=True)['frameTree']): if self._is_inner_frame():
self._is_diff_domain = False self._is_diff_domain = False
self.frame_page = None self.frame_page = None
backend_id = node.get('contentDocument', None).get('backendNodeId', None) backend_id = node.get('contentDocument', None).get('backendNodeId', None)
@ -53,6 +53,10 @@ class ChromiumFrame(object):
attrs = [f"{attr}='{attrs[attr]}'" for attr in attrs] attrs = [f"{attr}='{attrs[attr]}'" for attr in attrs]
return f'<ChromiumFrame {self.frame_ele.tag} {" ".join(attrs)}>' return f'<ChromiumFrame {self.frame_ele.tag} {" ".join(attrs)}>'
def _is_inner_frame(self):
"""返回当前frame是否同域"""
return self.frame_id in str(self.page.run_cdp('Page.getFrameTree', not_change=True)['frameTree'])
@property @property
def tag(self): def tag(self):
"""返回元素tag""" """返回元素tag"""
@ -149,7 +153,7 @@ class ChromiumFrame(object):
return self.frame_ele.css_path return self.frame_ele.css_path
def get(self, url, show_errmsg=False, retry=None, interval=None, timeout=None): def get(self, url, show_errmsg=False, retry=None, interval=None, timeout=None):
"""访问目标网页 \n """访问目标网页url为同域名时只有url参数生效 \n
:param url: 目标url :param url: 目标url
:param show_errmsg: 是否显示和抛出异常 :param show_errmsg: 是否显示和抛出异常
:param retry: 重试次数 :param retry: 重试次数
@ -157,7 +161,7 @@ class ChromiumFrame(object):
:param timeout: 连接超时时间 :param timeout: 连接超时时间
:return: 目标url是否可用 :return: 目标url是否可用
""" """
# todo: 处理跳转到异域的情况 # todo: 处理同域名跳转到异域,及同域跳转到异域的情况
if self._is_diff_domain: if self._is_diff_domain:
return self.frame_page.get(url, show_errmsg, retry, interval, timeout) return self.frame_page.get(url, show_errmsg, retry, interval, timeout)
else: else:

View File

@ -19,7 +19,7 @@ class ChromiumFrame(object):
self.frame_ele: ChromiumElement = ... self.frame_ele: ChromiumElement = ...
self.frame_page: ChromiumBase = ... self.frame_page: ChromiumBase = ...
self.page: ChromiumBase = ... self.page: ChromiumBase = ...
self._doc_ele: ChromiumElement =... self._doc_ele: ChromiumElement = ...
self.frame_id: str = ... self.frame_id: str = ...
self._is_diff_domain: bool = ... self._is_diff_domain: bool = ...
self.is_loading: bool = ... self.is_loading: bool = ...
@ -30,6 +30,8 @@ class ChromiumFrame(object):
def __repr__(self) -> str: ... def __repr__(self) -> str: ...
def _is_inner_frame(self) -> bool: ...
@property @property
def tag(self) -> str: ... def tag(self) -> str: ...