mirror of
https://gitee.com/g1879/DrissionPage.git
synced 2024-12-10 04:00:23 +08:00
3.0.5。避免不同线程重复获取document;修复save()中调用tab_id属性错误
This commit is contained in:
parent
048890a3d2
commit
7a509e511e
@ -517,7 +517,7 @@ class ChromiumElement(DrissionElement):
|
||||
|
||||
node = self.page.driver.DOM.describeNode(nodeId=self._node_id)['node']
|
||||
frame = node.get('frameId', None)
|
||||
frame = frame or self.page.current_tab_id
|
||||
frame = frame or self.page.tab_id
|
||||
result = self.page.driver.Page.getResourceContent(frameId=frame, url=src)
|
||||
if result['base64Encoded']:
|
||||
from base64 import b64decode
|
||||
@ -1091,6 +1091,7 @@ class ChromiumBase(BasePage):
|
||||
self._control_session = Session()
|
||||
self._control_session.keep_alive = False
|
||||
self._first_run = True
|
||||
self._is_reading = False # 用于避免不同线程重复读取document
|
||||
|
||||
self.address = addr_tab_opts
|
||||
if not tab_id:
|
||||
@ -1121,10 +1122,13 @@ class ChromiumBase(BasePage):
|
||||
def _get_document(self) -> None:
|
||||
"""刷新cdp使用的document数据"""
|
||||
# print('get doc')
|
||||
self._wait_loading()
|
||||
root_id = self._tab_obj.DOM.getDocument()['root']['nodeId']
|
||||
self._root_id = self._tab_obj.DOM.resolveNode(nodeId=root_id)['object']['objectId']
|
||||
self._is_loading = False
|
||||
if not self._is_reading:
|
||||
self._is_reading = True
|
||||
self._wait_loading()
|
||||
root_id = self._tab_obj.DOM.getDocument()['root']['nodeId']
|
||||
self._root_id = self._tab_obj.DOM.resolveNode(nodeId=root_id)['object']['objectId']
|
||||
self._is_loading = False
|
||||
self._is_reading = False
|
||||
|
||||
def _wait_loading(self, timeout: float = None) -> bool:
|
||||
"""等待页面加载完成
|
||||
@ -1778,6 +1782,7 @@ def make_chromium_ele(ele: ChromiumElement,
|
||||
:param loc: 元素定位元组
|
||||
:param single: True则返回第一个,False则返回全部
|
||||
:param timeout: 查找元素超时时间
|
||||
:param relative: WebPage用于标记是否相对定位使用
|
||||
:return: 返回ChromiumElement元素或它们组成的列表
|
||||
"""
|
||||
# ---------------处理定位符---------------
|
||||
|
@ -38,6 +38,7 @@ class ChromiumPage(ChromiumBase):
|
||||
:return: None
|
||||
"""
|
||||
self._is_loading = False
|
||||
self._is_reading = False
|
||||
self._root_id = None
|
||||
self.timeouts = Timeout(self)
|
||||
self._control_session = Session()
|
||||
|
@ -152,11 +152,13 @@ class DriverElement(DrissionElement):
|
||||
def _ele(self,
|
||||
loc_or_str: Union[Tuple[str, str], str],
|
||||
timeout: float = None,
|
||||
single: bool = True) -> Union['DriverElement', str, None, List[Union['DriverElement', str]]]:
|
||||
single: bool = True,
|
||||
relative: bool = False) -> Union['DriverElement', str, None, List[Union['DriverElement', str]]]:
|
||||
"""返回当前元素下级符合条件的子元素、属性或节点文本,默认返回第一个 \n
|
||||
:param loc_or_str: 元素的定位信息,可以是loc元组,或查询字符串
|
||||
:param timeout: 查找元素超时时间
|
||||
:param single: True则返回第一个,False则返回全部
|
||||
:param relative: WebPage用的表示是否相对定位的参数
|
||||
:return: DriverElement对象
|
||||
"""
|
||||
return make_driver_ele(self, loc_or_str, single, timeout)
|
||||
|
@ -244,11 +244,13 @@ class SessionElement(DrissionElement):
|
||||
def _ele(self,
|
||||
loc_or_str: Union[Tuple[str, str], str],
|
||||
timeout=None,
|
||||
single: bool = True) -> Union['SessionElement', str, None, List[Union['SessionElement', str]]]:
|
||||
single: bool = True,
|
||||
relative: bool = False) -> Union['SessionElement', str, None, List[Union['SessionElement', str]]]:
|
||||
"""返回当前元素下级符合条件的子元素、属性或节点文本,默认返回第一个 \n
|
||||
:param loc_or_str: 元素的定位信息,可以是loc元组,或查询字符串
|
||||
:param timeout: 不起实际作用,用于和父类对应
|
||||
:param single: True则返回第一个,False则返回全部
|
||||
:param relative: WebPage用的表示是否相对定位的参数
|
||||
:return: SessionElement对象
|
||||
"""
|
||||
return make_session_ele(self, loc_or_str, single)
|
||||
|
@ -182,11 +182,13 @@ class ShadowRootElement(BaseElement):
|
||||
def _ele(self,
|
||||
loc_or_str: Union[Tuple[str, str], str],
|
||||
timeout: float = None,
|
||||
single: bool = True) -> Union[DriverElement, str, None, List[Union[DriverElement, str]]]:
|
||||
single: bool = True,
|
||||
relative: bool = False) -> Union[DriverElement, str, None, List[Union[DriverElement, str]]]:
|
||||
"""返回当前元素下级符合条件的子元素,默认返回第一个 \n
|
||||
:param loc_or_str: 元素的定位信息,可以是loc元组,或查询字符串
|
||||
:param timeout: 查找元素超时时间
|
||||
:param single: True则返回第一个,False则返回全部
|
||||
:param relative: WebPage用的表示是否相对定位的参数
|
||||
:return: DriverElement对象
|
||||
"""
|
||||
# 先转换为sessionElement,再获取所有元素,获取它们的css selector路径,再用路径在页面上执行查找
|
||||
|
2
setup.py
2
setup.py
@ -6,7 +6,7 @@ with open("README.md", "r", encoding='utf-8') as fh:
|
||||
|
||||
setup(
|
||||
name="DrissionPage",
|
||||
version="3.0.2",
|
||||
version="3.0.5",
|
||||
author="g1879",
|
||||
author_email="g1879@qq.com",
|
||||
description="A module that integrates selenium and requests session, encapsulates common page operations.",
|
||||
|
Loading…
x
Reference in New Issue
Block a user