mirror of
https://gitee.com/g1879/DrissionPage.git
synced 2024-12-10 04:00:23 +08:00
4.0.0b21run_js()等待环境;
This commit is contained in:
parent
0cc81621de
commit
cd9439be5c
@ -13,4 +13,4 @@ from ._configs.chromium_options import ChromiumOptions
|
|||||||
from ._configs.session_options import SessionOptions
|
from ._configs.session_options import SessionOptions
|
||||||
|
|
||||||
__all__ = ['ChromiumPage', 'ChromiumOptions', 'SessionOptions', 'SessionPage', 'WebPage', '__version__']
|
__all__ = ['ChromiumPage', 'ChromiumOptions', 'SessionOptions', 'SessionPage', 'WebPage', '__version__']
|
||||||
__version__ = '4.0.0b20'
|
__version__ = '4.0.0b21'
|
||||||
|
@ -1279,13 +1279,19 @@ def run_js(page_or_ele, script, as_expr=False, timeout=None, args=None):
|
|||||||
:return: js执行结果
|
:return: js执行结果
|
||||||
"""
|
"""
|
||||||
if isinstance(page_or_ele, (ChromiumElement, ShadowRoot)):
|
if isinstance(page_or_ele, (ChromiumElement, ShadowRoot)):
|
||||||
|
is_page = False
|
||||||
page = page_or_ele.page
|
page = page_or_ele.page
|
||||||
obj_id = page_or_ele._obj_id
|
obj_id = page_or_ele._obj_id
|
||||||
is_page = False
|
|
||||||
else:
|
else:
|
||||||
page = page_or_ele
|
|
||||||
obj_id = page_or_ele._root_id
|
|
||||||
is_page = True
|
is_page = True
|
||||||
|
page = page_or_ele
|
||||||
|
end_time = perf_counter() + 5
|
||||||
|
while perf_counter() < end_time:
|
||||||
|
obj_id = page_or_ele._root_id
|
||||||
|
if obj_id is not None:
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
raise RuntimeError('js运行环境出错。')
|
||||||
|
|
||||||
if page.states.has_alert:
|
if page.states.has_alert:
|
||||||
raise AlertExistsError
|
raise AlertExistsError
|
||||||
|
@ -155,9 +155,12 @@ class ChromiumBase(BasePage):
|
|||||||
return
|
return
|
||||||
timeout = timeout if timeout >= .5 else .5
|
timeout = timeout if timeout >= .5 else .5
|
||||||
self._is_reading = True
|
self._is_reading = True
|
||||||
|
end_time = perf_counter() + timeout
|
||||||
try:
|
try:
|
||||||
b_id = self.run_cdp('DOM.getDocument', _timeout=timeout)['root']['backendNodeId']
|
b_id = self.run_cdp('DOM.getDocument', _timeout=timeout)['root']['backendNodeId']
|
||||||
self._root_id = self.run_cdp('DOM.resolveNode', backendNodeId=b_id, _timeout=1)['object']['objectId']
|
timeout = end_time - perf_counter()
|
||||||
|
timeout = .5 if timeout < 0 else timeout
|
||||||
|
self._root_id = self.run_cdp('DOM.resolveNode', backendNodeId=b_id, _timeout=timeout)['object']['objectId']
|
||||||
|
|
||||||
r = self.run_cdp('Page.getFrameTree')
|
r = self.run_cdp('Page.getFrameTree')
|
||||||
for i in findall(r"'id': '(.*?)'", str(r)):
|
for i in findall(r"'id': '(.*?)'", str(r)):
|
||||||
@ -168,8 +171,10 @@ class ChromiumBase(BasePage):
|
|||||||
|
|
||||||
except:
|
except:
|
||||||
if self._debug:
|
if self._debug:
|
||||||
print('获取文档失败')
|
print('获取文档失败。')
|
||||||
return False
|
print('请把报错信息和重现方法告知作者,感谢。\nhttps://gitee.com/g1879/DrissionPage/issues/new')
|
||||||
|
raise
|
||||||
|
# return False
|
||||||
|
|
||||||
finally:
|
finally:
|
||||||
self._is_loading = False
|
self._is_loading = False
|
||||||
|
2
setup.py
2
setup.py
@ -6,7 +6,7 @@ with open("README.md", "r", encoding='utf-8') as fh:
|
|||||||
|
|
||||||
setup(
|
setup(
|
||||||
name="DrissionPage",
|
name="DrissionPage",
|
||||||
version="4.0.0b20",
|
version="4.0.0b21",
|
||||||
author="g1879",
|
author="g1879",
|
||||||
author_email="g1879@qq.com",
|
author_email="g1879@qq.com",
|
||||||
description="Python based web automation tool. It can control the browser and send and receive data packets.",
|
description="Python based web automation tool. It can control the browser and send and receive data packets.",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user