mirror of
https://gitee.com/g1879/DrissionPage.git
synced 2024-12-10 04:00:23 +08:00
影元素增加child()和children();相对定位方法增加ele_only参数
This commit is contained in:
parent
de9ec26418
commit
058b9b3c55
@ -71,7 +71,7 @@ class BaseElement(BaseParser):
|
||||
pass
|
||||
|
||||
def _ele(self, loc_or_str, timeout=None, single=True, relative=False, raise_err=None):
|
||||
r = self._find_elements(loc_or_str, timeout=timeout, single=single, relative=relative, raise_err=raise_err)
|
||||
r = self._find_elements(loc_or_str, timeout=timeout, single=single, relative=relative, raise_err=raise_err)
|
||||
if not single or raise_err is False:
|
||||
return r
|
||||
if not r and (Settings.raise_ele_not_found or raise_err is True):
|
||||
@ -140,14 +140,15 @@ class DrissionElement(BaseElement):
|
||||
|
||||
return self._ele(loc, timeout=0, relative=True, raise_err=False)
|
||||
|
||||
def child(self, index=1, filter_loc='', timeout=None):
|
||||
def child(self, index=1, filter_loc='', timeout=None, ele_only=True):
|
||||
"""返回直接子元素元素或节点组成的列表,可用查询语法筛选
|
||||
:param index: 第几个查询结果元素,1开始
|
||||
:param filter_loc: 用于筛选元素的查询语法
|
||||
:param timeout: 查找元素的超时时间
|
||||
:param index: 第几个查询结果,1开始
|
||||
:param filter_loc: 用于筛选的查询语法
|
||||
:param timeout: 查找节点的超时时间
|
||||
:param ele_only: 是否只获取元素,为False时把文本、注释节点也纳入
|
||||
:return: 直接子元素或节点文本组成的列表
|
||||
"""
|
||||
nodes = self.children(filter_loc=filter_loc, timeout=timeout)
|
||||
nodes = self.children(filter_loc=filter_loc, timeout=timeout, ele_only=ele_only)
|
||||
if not nodes:
|
||||
if Settings.raise_ele_not_found:
|
||||
raise ElementNotFoundError
|
||||
@ -162,14 +163,79 @@ class DrissionElement(BaseElement):
|
||||
else:
|
||||
return NoneElement()
|
||||
|
||||
def children(self, filter_loc='', timeout=None):
|
||||
def prev(self, index=1, filter_loc='', timeout=0, ele_only=True):
|
||||
"""返回前面的一个兄弟元素,可用查询语法筛选,可指定返回筛选结果的第几个
|
||||
:param index: 前面第几个查询结果,1开始
|
||||
:param filter_loc: 用于筛选的查询语法
|
||||
:param timeout: 查找节点的超时时间
|
||||
:param ele_only: 是否只获取元素,为False时把文本、注释节点也纳入
|
||||
:return: 兄弟元素
|
||||
"""
|
||||
nodes = self._get_brothers(index, filter_loc, 'preceding', timeout=timeout, ele_only=ele_only)
|
||||
if nodes:
|
||||
return nodes[-1]
|
||||
if Settings.raise_ele_not_found:
|
||||
raise ElementNotFoundError
|
||||
else:
|
||||
return NoneElement()
|
||||
|
||||
def next(self, index=1, filter_loc='', timeout=0, ele_only=True):
|
||||
"""返回后面的一个兄弟元素,可用查询语法筛选,可指定返回筛选结果的第几个
|
||||
:param index: 后面第几个查询结果,1开始
|
||||
:param filter_loc: 用于筛选的查询语法
|
||||
:param timeout: 查找节点的超时时间
|
||||
:param ele_only: 是否只获取元素,为False时把文本、注释节点也纳入
|
||||
:return: 兄弟元素
|
||||
"""
|
||||
nodes = self._get_brothers(index, filter_loc, 'following', timeout=timeout, ele_only=ele_only)
|
||||
if nodes:
|
||||
return nodes[0]
|
||||
if Settings.raise_ele_not_found:
|
||||
raise ElementNotFoundError
|
||||
else:
|
||||
return NoneElement()
|
||||
|
||||
def before(self, index=1, filter_loc='', timeout=None, ele_only=True):
|
||||
"""返回前面的一个兄弟元素,可用查询语法筛选,可指定返回筛选结果的第几个
|
||||
:param index: 前面第几个查询结果,1开始
|
||||
:param filter_loc: 用于筛选的查询语法
|
||||
:param timeout: 查找节点的超时时间
|
||||
:param ele_only: 是否只获取元素,为False时把文本、注释节点也纳入
|
||||
:return: 本元素前面的某个元素或节点
|
||||
"""
|
||||
nodes = self._get_brothers(index, filter_loc, 'preceding', False, timeout=timeout, ele_only=ele_only)
|
||||
if nodes:
|
||||
return nodes[-1]
|
||||
if Settings.raise_ele_not_found:
|
||||
raise ElementNotFoundError
|
||||
else:
|
||||
return NoneElement()
|
||||
|
||||
def after(self, index=1, filter_loc='', timeout=None, ele_only=True):
|
||||
"""返回后面的一个兄弟元素,可用查询语法筛选,可指定返回筛选结果的第几个
|
||||
:param index: 后面第几个查询结果,1开始
|
||||
:param filter_loc: 用于筛选的查询语法
|
||||
:param timeout: 查找节点的超时时间
|
||||
:param ele_only: 是否只获取元素,为False时把文本、注释节点也纳入
|
||||
:return: 本元素后面的某个元素或节点
|
||||
"""
|
||||
nodes = self._get_brothers(index, filter_loc, 'following', False, timeout, ele_only=ele_only)
|
||||
if nodes:
|
||||
return nodes[0]
|
||||
if Settings.raise_ele_not_found:
|
||||
raise ElementNotFoundError
|
||||
else:
|
||||
return NoneElement()
|
||||
|
||||
def children(self, filter_loc='', timeout=None, ele_only=True):
|
||||
"""返回直接子元素元素或节点组成的列表,可用查询语法筛选
|
||||
:param filter_loc: 用于筛选元素的查询语法
|
||||
:param timeout: 查找元素的超时时间
|
||||
:param filter_loc: 用于筛选的查询语法
|
||||
:param timeout: 查找节点的超时时间
|
||||
:param ele_only: 是否只获取元素,为False时把文本、注释节点也纳入
|
||||
:return: 直接子元素或节点文本组成的列表
|
||||
"""
|
||||
if not filter_loc:
|
||||
loc = '*'
|
||||
loc = '*' if ele_only else 'node()'
|
||||
else:
|
||||
loc = get_loc(filter_loc, True) # 把定位符转换为xpath
|
||||
if loc[0] == 'css selector':
|
||||
@ -180,102 +246,49 @@ class DrissionElement(BaseElement):
|
||||
nodes = self._ele(loc, timeout=timeout, single=False, relative=True)
|
||||
return [e for e in nodes if not (isinstance(e, str) and sub('[ \n\t\r]', '', e) == '')]
|
||||
|
||||
def prev(self, index=1, filter_loc='', timeout=0):
|
||||
"""返回前面的一个兄弟元素,可用查询语法筛选,可指定返回筛选结果的第几个
|
||||
:param index: 前面第几个查询结果元素,1开始
|
||||
:param filter_loc: 用于筛选元素的查询语法
|
||||
:param timeout: 查找元素的超时时间
|
||||
:return: 兄弟元素
|
||||
"""
|
||||
nodes = self._get_brothers(index, filter_loc, 'preceding', timeout=timeout)
|
||||
if nodes:
|
||||
return nodes[-1]
|
||||
if Settings.raise_ele_not_found:
|
||||
raise ElementNotFoundError
|
||||
else:
|
||||
return NoneElement()
|
||||
|
||||
def next(self, index=1, filter_loc='', timeout=0):
|
||||
"""返回后面的一个兄弟元素,可用查询语法筛选,可指定返回筛选结果的第几个
|
||||
:param index: 后面第几个查询结果元素,1开始
|
||||
:param filter_loc: 用于筛选元素的查询语法
|
||||
:param timeout: 查找元素的超时时间
|
||||
:return: 兄弟元素
|
||||
"""
|
||||
nodes = self._get_brothers(index, filter_loc, 'following', timeout=timeout)
|
||||
if nodes:
|
||||
return nodes[0]
|
||||
if Settings.raise_ele_not_found:
|
||||
raise ElementNotFoundError
|
||||
else:
|
||||
return NoneElement()
|
||||
|
||||
def before(self, index=1, filter_loc='', timeout=None):
|
||||
"""返回前面的一个兄弟元素,可用查询语法筛选,可指定返回筛选结果的第几个
|
||||
:param index: 前面第几个查询结果元素,1开始
|
||||
:param filter_loc: 用于筛选元素的查询语法
|
||||
:param timeout: 查找元素的超时时间
|
||||
:return: 本元素前面的某个元素或节点
|
||||
"""
|
||||
nodes = self._get_brothers(index, filter_loc, 'preceding', False, timeout=timeout)
|
||||
if nodes:
|
||||
return nodes[-1]
|
||||
if Settings.raise_ele_not_found:
|
||||
raise ElementNotFoundError
|
||||
else:
|
||||
return NoneElement()
|
||||
|
||||
def after(self, index=1, filter_loc='', timeout=None):
|
||||
"""返回后面的一个兄弟元素,可用查询语法筛选,可指定返回筛选结果的第几个
|
||||
:param index: 后面第几个查询结果元素,1开始
|
||||
:param filter_loc: 用于筛选元素的查询语法
|
||||
:param timeout: 查找元素的超时时间
|
||||
:return: 本元素后面的某个元素或节点
|
||||
"""
|
||||
nodes = self._get_brothers(index, filter_loc, 'following', False, timeout)
|
||||
if nodes:
|
||||
return nodes[0]
|
||||
if Settings.raise_ele_not_found:
|
||||
raise ElementNotFoundError
|
||||
else:
|
||||
return NoneElement()
|
||||
|
||||
def prevs(self, filter_loc='', timeout=0):
|
||||
def prevs(self, filter_loc='', timeout=0, ele_only=True):
|
||||
"""返回前面全部兄弟元素或节点组成的列表,可用查询语法筛选
|
||||
:param filter_loc: 用于筛选元素的查询语法
|
||||
:param timeout: 查找元素的超时时间
|
||||
:param filter_loc: 用于筛选的查询语法
|
||||
:param timeout: 查找节点的超时时间
|
||||
:param ele_only: 是否只获取元素,为False时把文本、注释节点也纳入
|
||||
:return: 兄弟元素或节点文本组成的列表
|
||||
"""
|
||||
return self._get_brothers(filter_loc=filter_loc, direction='preceding', timeout=timeout)
|
||||
return self._get_brothers(filter_loc=filter_loc, direction='preceding', timeout=timeout, ele_only=ele_only)
|
||||
|
||||
def nexts(self, filter_loc='', timeout=0):
|
||||
def nexts(self, filter_loc='', timeout=0, ele_only=True):
|
||||
"""返回后面全部兄弟元素或节点组成的列表,可用查询语法筛选
|
||||
:param filter_loc: 用于筛选元素的查询语法
|
||||
:param timeout: 查找元素的超时时间
|
||||
:param filter_loc: 用于筛选的查询语法
|
||||
:param timeout: 查找节点的超时时间
|
||||
:param ele_only: 是否只获取元素,为False时把文本、注释节点也纳入
|
||||
:return: 兄弟元素或节点文本组成的列表
|
||||
"""
|
||||
return self._get_brothers(filter_loc=filter_loc, direction='following', timeout=timeout)
|
||||
return self._get_brothers(filter_loc=filter_loc, direction='following', timeout=timeout, ele_only=ele_only)
|
||||
|
||||
def befores(self, filter_loc='', timeout=None):
|
||||
def befores(self, filter_loc='', timeout=None, ele_only=True):
|
||||
"""返回后面全部兄弟元素或节点组成的列表,可用查询语法筛选
|
||||
:param filter_loc: 用于筛选元素的查询语法
|
||||
:param timeout: 查找元素的超时时间
|
||||
:param filter_loc: 用于筛选的查询语法
|
||||
:param timeout: 查找节点的超时时间
|
||||
:param ele_only: 是否只获取元素,为False时把文本、注释节点也纳入
|
||||
:return: 本元素前面的元素或节点组成的列表
|
||||
"""
|
||||
return self._get_brothers(filter_loc=filter_loc, direction='preceding', brother=False, timeout=timeout)
|
||||
return self._get_brothers(filter_loc=filter_loc, direction='preceding',
|
||||
brother=False, timeout=timeout, ele_only=ele_only)
|
||||
|
||||
def afters(self, filter_loc='', timeout=None):
|
||||
def afters(self, filter_loc='', timeout=None, ele_only=True):
|
||||
"""返回前面全部兄弟元素或节点组成的列表,可用查询语法筛选
|
||||
:param filter_loc: 用于筛选元素的查询语法
|
||||
:param timeout: 查找元素的超时时间
|
||||
:param filter_loc: 用于筛选的查询语法
|
||||
:param timeout: 查找节点的超时时间
|
||||
:param ele_only: 是否只获取元素,为False时把文本、注释节点也纳入
|
||||
:return: 本元素后面的元素或节点组成的列表
|
||||
"""
|
||||
return self._get_brothers(filter_loc=filter_loc, direction='following', brother=False, timeout=timeout)
|
||||
return self._get_brothers(filter_loc=filter_loc, direction='following',
|
||||
brother=False, timeout=timeout, ele_only=ele_only)
|
||||
|
||||
def _get_brothers(self, index=None, filter_loc='', direction='following', brother=True, timeout=.5):
|
||||
def _get_brothers(self, index=None, filter_loc='', direction='following',
|
||||
brother=True, timeout=.5, ele_only=True):
|
||||
"""按要求返回兄弟元素或节点组成的列表
|
||||
:param index: 获取第几个,该参数不为None时只获取该编号的元素
|
||||
:param filter_loc: 用于筛选元素的查询语法
|
||||
:param filter_loc: 用于筛选的查询语法
|
||||
:param direction: 'following' 或 'preceding',查找的方向
|
||||
:param brother: 查找范围,在同级查找还是整个dom前后查找
|
||||
:param timeout: 查找等待时间
|
||||
@ -287,7 +300,7 @@ class DrissionElement(BaseElement):
|
||||
brother = '-sibling' if brother else ''
|
||||
|
||||
if not filter_loc:
|
||||
loc = '*'
|
||||
loc = '*' if ele_only else 'node()'
|
||||
|
||||
else:
|
||||
loc = get_loc(filter_loc, True) # 把定位符转换为xpath
|
||||
@ -399,7 +412,7 @@ class BasePage(BaseParser):
|
||||
def _ele(self, loc_or_ele, timeout=None, single=True, raise_err=None):
|
||||
if not loc_or_ele:
|
||||
raise ElementNotFoundError
|
||||
r = self._find_elements(loc_or_ele, timeout=timeout, single=single, raise_err=raise_err)
|
||||
r = self._find_elements(loc_or_ele, timeout=timeout, single=single, raise_err=raise_err)
|
||||
if not single or raise_err is False:
|
||||
return r
|
||||
if not r and (Settings().raise_ele_not_found is True or raise_err is True):
|
||||
|
@ -80,57 +80,57 @@ class DrissionElement(BaseElement):
|
||||
|
||||
def parent(self, level_or_loc: Union[tuple, str, int] = 1) -> Union[DrissionElement, None]: ...
|
||||
|
||||
def child(self,
|
||||
index: int = 1,
|
||||
def child(self, index: int = 1,
|
||||
filter_loc: Union[tuple, str] = '',
|
||||
timeout: float = 0) -> Union[DrissionElement, str, NoneElement]: ...
|
||||
timeout: float = None,
|
||||
ele_only: bool = True) -> Union[DrissionElement, str, NoneElement]: ...
|
||||
|
||||
def children(self,
|
||||
filter_loc: Union[tuple, str] = '',
|
||||
timeout: float = 0) -> List[Union[DrissionElement, str]]: ...
|
||||
|
||||
def prev(self,
|
||||
index: int = 1,
|
||||
def prev(self, index: int = 1,
|
||||
filter_loc: Union[tuple, str] = '',
|
||||
timeout: float = 0) -> Union[DrissionElement, str, NoneElement]: ...
|
||||
timeout: float = 0,
|
||||
ele_only: bool = True) -> Union[DrissionElement, str, NoneElement]: ...
|
||||
|
||||
def next(self,
|
||||
index: int = 1,
|
||||
def next(self, index: int = 1,
|
||||
filter_loc: Union[tuple, str] = '',
|
||||
timeout: float = 0) -> Union[DrissionElement, str, NoneElement]: ...
|
||||
timeout: float = 0,
|
||||
ele_only: bool = True) -> Union[DrissionElement, str, NoneElement]: ...
|
||||
|
||||
def before(self,
|
||||
index: int = 1,
|
||||
def before(self, index: int = 1,
|
||||
filter_loc: Union[tuple, str] = '',
|
||||
timeout: float = None) -> Union[DrissionElement, str, NoneElement]: ...
|
||||
timeout: float = None,
|
||||
ele_only: bool = True) -> Union[DrissionElement, str, NoneElement]: ...
|
||||
|
||||
def after(self,
|
||||
index: int = 1,
|
||||
def after(self, index: int = 1,
|
||||
filter_loc: Union[tuple, str] = '',
|
||||
timeout: float = None) -> Union[DrissionElement, str, NoneElement]: ...
|
||||
timeout: float = None,
|
||||
ele_only: bool = True) -> Union[DrissionElement, str, NoneElement]: ...
|
||||
|
||||
def prevs(self,
|
||||
filter_loc: Union[tuple, str] = '',
|
||||
timeout: float = 0) -> List[Union[DrissionElement, str]]: ...
|
||||
def children(self, filter_loc: Union[tuple, str] = '',
|
||||
timeout: float = None,
|
||||
ele_only: bool = True) -> List[Union[DrissionElement, str]]: ...
|
||||
|
||||
def nexts(self,
|
||||
filter_loc: Union[tuple, str] = '',
|
||||
timeout: float = 0) -> List[Union[DrissionElement, str]]: ...
|
||||
def prevs(self, filter_loc: Union[tuple, str] = '',
|
||||
timeout: float = 0,
|
||||
ele_only: bool = True) -> List[Union[DrissionElement, str]]: ...
|
||||
|
||||
def befores(self,
|
||||
filter_loc: Union[tuple, str] = '',
|
||||
timeout: float = None) -> List[Union[DrissionElement, str]]: ...
|
||||
def nexts(self, filter_loc: Union[tuple, str] = '',
|
||||
timeout: float = 0,
|
||||
ele_only: bool = True) -> List[Union[DrissionElement, str]]: ...
|
||||
|
||||
def afters(self,
|
||||
filter_loc: Union[tuple, str] = '',
|
||||
timeout: float = None) -> List[Union[DrissionElement, str]]: ...
|
||||
def befores(self, filter_loc: Union[tuple, str] = '',
|
||||
timeout: float = None,
|
||||
ele_only: bool = True) -> List[Union[DrissionElement, str]]: ...
|
||||
|
||||
def _get_brothers(self,
|
||||
index: int = None,
|
||||
def afters(self, filter_loc: Union[tuple, str] = '',
|
||||
timeout: float = None,
|
||||
ele_only: bool = True) -> List[Union[DrissionElement, str]]: ...
|
||||
|
||||
def _get_brothers(self, index: int = None,
|
||||
filter_loc: Union[tuple, str] = '',
|
||||
direction: str = 'following',
|
||||
brother: bool = True,
|
||||
timeout: float = 0.5) -> List[Union[DrissionElement, str]]: ...
|
||||
timeout: float = 0.5,
|
||||
ele_only: bool = True) -> List[Union[DrissionElement, str]]: ...
|
||||
|
||||
# ----------------以下属性或方法由后代实现----------------
|
||||
@property
|
||||
|
@ -207,73 +207,104 @@ class ChromiumElement(DrissionElement):
|
||||
"""
|
||||
return super().parent(level_or_loc)
|
||||
|
||||
def prev(self, filter_loc='', index=1, timeout=0):
|
||||
"""返回前面的一个兄弟元素,可用查询语法筛选,可指定返回筛选结果的第几个
|
||||
:param filter_loc: 用于筛选元素的查询语法
|
||||
:param index: 前面第几个查询结果元素
|
||||
:param timeout: 查找元素的超时时间
|
||||
:return: 兄弟元素
|
||||
def child(self, filter_loc='', index=1, timeout=0, ele_only=True):
|
||||
"""返回当前元素的一个符合条件的直接子元素,可用查询语法筛选,可指定返回筛选结果的第几个
|
||||
:param filter_loc: 用于筛选的查询语法
|
||||
:param index: 第几个查询结果,1开始
|
||||
:param timeout: 查找节点的超时时间
|
||||
:param ele_only: 是否只获取元素,为False时把文本、注释节点也纳入
|
||||
:return: 直接子元素或节点文本
|
||||
"""
|
||||
return super().prev(index, filter_loc, timeout)
|
||||
return super().child(index, filter_loc, timeout, ele_only=ele_only)
|
||||
|
||||
def next(self, filter_loc='', index=1, timeout=0):
|
||||
"""返回后面的一个兄弟元素,可用查询语法筛选,可指定返回筛选结果的第几个
|
||||
:param filter_loc: 用于筛选元素的查询语法
|
||||
:param index: 后面第几个查询结果元素
|
||||
:param timeout: 查找元素的超时时间
|
||||
:return: 兄弟元素
|
||||
def prev(self, filter_loc='', index=1, timeout=0, ele_only=True):
|
||||
"""返回当前元素前面一个符合条件的同级元素,可用查询语法筛选,可指定返回筛选结果的第几个
|
||||
:param filter_loc: 用于筛选的查询语法
|
||||
:param index: 前面第几个查询结果,1开始
|
||||
:param timeout: 查找节点的超时时间
|
||||
:param ele_only: 是否只获取元素,为False时把文本、注释节点也纳入
|
||||
:return: 兄弟元素或节点文本
|
||||
"""
|
||||
return super().next(index, filter_loc, timeout)
|
||||
return super().prev(index, filter_loc, timeout, ele_only=ele_only)
|
||||
|
||||
def before(self, filter_loc='', index=1, timeout=None):
|
||||
"""返回当前元素前面的一个元素,可指定筛选条件和第几个。查找范围不限兄弟元素,而是整个DOM文档
|
||||
:param filter_loc: 用于筛选元素的查询语法
|
||||
:param index: 前面第几个查询结果元素
|
||||
:param timeout: 查找元素的超时时间
|
||||
def next(self, filter_loc='', index=1, timeout=0, ele_only=True):
|
||||
"""返回当前元素后面一个符合条件的同级元素,可用查询语法筛选,可指定返回筛选结果的第几个
|
||||
:param filter_loc: 用于筛选的查询语法
|
||||
:param index: 第几个查询结果,1开始
|
||||
:param timeout: 查找节点的超时时间
|
||||
:param ele_only: 是否只获取元素,为False时把文本、注释节点也纳入
|
||||
:return: 兄弟元素或节点文本
|
||||
"""
|
||||
return super().next(index, filter_loc, timeout, ele_only=ele_only)
|
||||
|
||||
def before(self, filter_loc='', index=1, timeout=None, ele_only=True):
|
||||
"""返回文档中当前元素前面符合条件的第一个元素,可用查询语法筛选,可指定返回筛选结果的第几个
|
||||
查找范围不限同级元素,而是整个DOM文档
|
||||
:param filter_loc: 用于筛选的查询语法
|
||||
:param index: 前面第几个查询结果,1开始
|
||||
:param timeout: 查找节点的超时时间
|
||||
:param ele_only: 是否只获取元素,为False时把文本、注释节点也纳入
|
||||
:return: 本元素前面的某个元素或节点
|
||||
"""
|
||||
return super().before(index, filter_loc, timeout)
|
||||
return super().before(index, filter_loc, timeout, ele_only=ele_only)
|
||||
|
||||
def after(self, filter_loc='', index=1, timeout=None):
|
||||
"""返回当前元素后面的一个元素,可指定筛选条件和第几个。查找范围不限兄弟元素,而是整个DOM文档
|
||||
:param filter_loc: 用于筛选元素的查询语法
|
||||
:param index: 后面第几个查询结果元素
|
||||
:param timeout: 查找元素的超时时间
|
||||
def after(self, filter_loc='', index=1, timeout=None, ele_only=True):
|
||||
"""返回文档中此当前元素后面符合条件的第一个元素,可用查询语法筛选,可指定返回筛选结果的第几个
|
||||
查找范围不限同级元素,而是整个DOM文档
|
||||
:param filter_loc: 用于筛选的查询语法
|
||||
:param index: 第几个查询结果,1开始
|
||||
:param timeout: 查找节点的超时时间
|
||||
:param ele_only: 是否只获取元素,为False时把文本、注释节点也纳入
|
||||
:return: 本元素后面的某个元素或节点
|
||||
"""
|
||||
return super().after(index, filter_loc, timeout)
|
||||
return super().after(index, filter_loc, timeout, ele_only=ele_only)
|
||||
|
||||
def prevs(self, filter_loc='', timeout=0):
|
||||
"""返回前面全部兄弟元素或节点组成的列表,可用查询语法筛选
|
||||
:param filter_loc: 用于筛选元素的查询语法
|
||||
:param timeout: 查找元素的超时时间
|
||||
def children(self, filter_loc='', timeout=0, ele_only=True):
|
||||
"""返回当前元素符合条件的直接子元素或节点组成的列表,可用查询语法筛选
|
||||
:param filter_loc: 用于筛选的查询语法
|
||||
:param timeout: 查找节点的超时时间
|
||||
:param ele_only: 是否只获取元素,为False时把文本、注释节点也纳入
|
||||
:return: 直接子元素或节点文本组成的列表
|
||||
"""
|
||||
return super().children(filter_loc, timeout, ele_only=ele_only)
|
||||
|
||||
def prevs(self, filter_loc='', timeout=0, ele_only=True):
|
||||
"""返回当前元素前面符合条件的同级元素或节点组成的列表,可用查询语法筛选
|
||||
:param filter_loc: 用于筛选的查询语法
|
||||
:param timeout: 查找节点的超时时间
|
||||
:param ele_only: 是否只获取元素,为False时把文本、注释节点也纳入
|
||||
:return: 兄弟元素或节点文本组成的列表
|
||||
"""
|
||||
return super().prevs(filter_loc, timeout)
|
||||
return super().prevs(filter_loc, timeout, ele_only=ele_only)
|
||||
|
||||
def nexts(self, filter_loc='', timeout=0):
|
||||
"""返回后面全部兄弟元素或节点组成的列表,可用查询语法筛选
|
||||
:param filter_loc: 用于筛选元素的查询语法
|
||||
:param timeout: 查找元素的超时时间
|
||||
def nexts(self, filter_loc='', timeout=0, ele_only=True):
|
||||
"""返回当前元素后面符合条件的同级元素或节点组成的列表,可用查询语法筛选
|
||||
:param filter_loc: 用于筛选的查询语法
|
||||
:param timeout: 查找节点的超时时间
|
||||
:param ele_only: 是否只获取元素,为False时把文本、注释节点也纳入
|
||||
:return: 兄弟元素或节点文本组成的列表
|
||||
"""
|
||||
return super().nexts(filter_loc, timeout)
|
||||
return super().nexts(filter_loc, timeout, ele_only=ele_only)
|
||||
|
||||
def befores(self, filter_loc='', timeout=None):
|
||||
"""返回当前元素后面符合条件的全部兄弟元素或节点组成的列表,可用查询语法筛选。查找范围不限兄弟元素,而是整个DOM文档
|
||||
:param filter_loc: 用于筛选元素的查询语法
|
||||
:param timeout: 查找元素的超时时间
|
||||
def befores(self, filter_loc='', timeout=None, ele_only=True):
|
||||
"""返回文档中当前元素前面符合条件的元素或节点组成的列表,可用查询语法筛选
|
||||
查找范围不限同级元素,而是整个DOM文档
|
||||
:param filter_loc: 用于筛选的查询语法
|
||||
:param timeout: 查找节点的超时时间
|
||||
:param ele_only: 是否只获取元素,为False时把文本、注释节点也纳入
|
||||
:return: 本元素前面的元素或节点组成的列表
|
||||
"""
|
||||
return super().befores(filter_loc, timeout)
|
||||
return super().befores(filter_loc, timeout, ele_only=ele_only)
|
||||
|
||||
def afters(self, filter_loc='', timeout=None):
|
||||
"""返回当前元素后面符合条件的全部兄弟元素或节点组成的列表,可用查询语法筛选。查找范围不限兄弟元素,而是整个DOM文档
|
||||
:param filter_loc: 用于筛选元素的查询语法
|
||||
:param timeout: 查找元素的超时时间
|
||||
:return: 本元素前面的元素或节点组成的列表
|
||||
def afters(self, filter_loc='', timeout=None, ele_only=True):
|
||||
"""返回文档中当前元素后面符合条件的元素或节点组成的列表,可用查询语法筛选
|
||||
查找范围不限同级元素,而是整个DOM文档
|
||||
:param filter_loc: 用于筛选的查询语法
|
||||
:param timeout: 查找节点的超时时间
|
||||
:param ele_only: 是否只获取元素,为False时把文本、注释节点也纳入
|
||||
:return: 本元素后面的元素或节点组成的列表
|
||||
"""
|
||||
return super().afters(filter_loc, timeout)
|
||||
return super().afters(filter_loc, timeout, ele_only=ele_only)
|
||||
|
||||
def attr(self, attr):
|
||||
"""返回一个attribute属性值
|
||||
@ -919,10 +950,31 @@ class ChromiumShadowRoot(BaseElement):
|
||||
|
||||
return self.parent_ele._ele(loc, timeout=0, relative=True, raise_err=False)
|
||||
|
||||
def child(self, filter_loc='', index=1):
|
||||
"""返回直接子元素元素或节点组成的列表,可用查询语法筛选
|
||||
:param filter_loc: 用于筛选的查询语法
|
||||
:param index: 第几个查询结果,1开始
|
||||
:return: 直接子元素或节点文本组成的列表
|
||||
"""
|
||||
nodes = self.children(filter_loc=filter_loc)
|
||||
if not nodes:
|
||||
if Settings.raise_ele_not_found:
|
||||
raise ElementNotFoundError
|
||||
else:
|
||||
return NoneElement()
|
||||
|
||||
try:
|
||||
return nodes[index - 1]
|
||||
except IndexError:
|
||||
if Settings.raise_ele_not_found:
|
||||
raise ElementNotFoundError
|
||||
else:
|
||||
return NoneElement()
|
||||
|
||||
def next(self, filter_loc='', index=1):
|
||||
"""返回后面的一个兄弟元素,可用查询语法筛选,可指定返回筛选结果的第几个
|
||||
:param filter_loc: 用于筛选元素的查询语法
|
||||
:param index: 第几个查询结果元素
|
||||
"""返回当前元素后面一个符合条件的同级元素,可用查询语法筛选,可指定返回筛选结果的第几个
|
||||
:param filter_loc: 用于筛选的查询语法
|
||||
:param index: 第几个查询结果,1开始
|
||||
:return: ChromiumElement对象
|
||||
"""
|
||||
nodes = self.nexts(filter_loc=filter_loc)
|
||||
@ -934,9 +986,10 @@ class ChromiumShadowRoot(BaseElement):
|
||||
return NoneElement()
|
||||
|
||||
def before(self, filter_loc='', index=1):
|
||||
"""返回前面的一个兄弟元素,可用查询语法筛选,可指定返回筛选结果的第几个
|
||||
:param filter_loc: 用于筛选元素的查询语法
|
||||
:param index: 前面第几个查询结果元素
|
||||
"""返回文档中当前元素前面符合条件的第一个元素,可用查询语法筛选,可指定返回筛选结果的第几个
|
||||
查找范围不限同级元素,而是整个DOM文档
|
||||
:param filter_loc: 用于筛选的查询语法
|
||||
:param index: 前面第几个查询结果,1开始
|
||||
:return: 本元素前面的某个元素或节点
|
||||
"""
|
||||
nodes = self.befores(filter_loc=filter_loc)
|
||||
@ -948,9 +1001,10 @@ class ChromiumShadowRoot(BaseElement):
|
||||
return NoneElement()
|
||||
|
||||
def after(self, filter_loc='', index=1):
|
||||
"""返回后面的一个兄弟元素,可用查询语法筛选,可指定返回筛选结果的第几个
|
||||
:param filter_loc: 用于筛选元素的查询语法
|
||||
:param index: 后面第几个查询结果元素
|
||||
"""返回文档中此当前元素后面符合条件的第一个元素,可用查询语法筛选,可指定返回筛选结果的第几个
|
||||
查找范围不限同级元素,而是整个DOM文档
|
||||
:param filter_loc: 用于筛选的查询语法
|
||||
:param index: 后面第几个查询结果,1开始
|
||||
:return: 本元素后面的某个元素或节点
|
||||
"""
|
||||
nodes = self.afters(filter_loc=filter_loc)
|
||||
@ -961,9 +1015,25 @@ class ChromiumShadowRoot(BaseElement):
|
||||
else:
|
||||
return NoneElement()
|
||||
|
||||
def children(self, filter_loc=''):
|
||||
"""返回当前元素符合条件的直接子元素或节点组成的列表,可用查询语法筛选
|
||||
:param filter_loc: 用于筛选的查询语法
|
||||
:return: 直接子元素或节点文本组成的列表
|
||||
"""
|
||||
if not filter_loc:
|
||||
loc = '*'
|
||||
else:
|
||||
loc = get_loc(filter_loc, True) # 把定位符转换为xpath
|
||||
if loc[0] == 'css selector':
|
||||
raise ValueError('此css selector语法不受支持,请换成xpath。')
|
||||
loc = loc[1].lstrip('./')
|
||||
|
||||
loc = f'xpath:./{loc}'
|
||||
return self._ele(loc, single=False, relative=True)
|
||||
|
||||
def nexts(self, filter_loc=''):
|
||||
"""返回后面所有兄弟元素或节点组成的列表
|
||||
:param filter_loc: 用于筛选元素的查询语法
|
||||
"""返回当前元素后面符合条件的同级元素或节点组成的列表,可用查询语法筛选
|
||||
:param filter_loc: 用于筛选的查询语法
|
||||
:return: ChromiumElement对象组成的列表
|
||||
"""
|
||||
loc = get_loc(filter_loc, True)
|
||||
@ -975,8 +1045,9 @@ class ChromiumShadowRoot(BaseElement):
|
||||
return self.parent_ele._ele(xpath, single=False, relative=True)
|
||||
|
||||
def befores(self, filter_loc=''):
|
||||
"""返回后面全部兄弟元素或节点组成的列表,可用查询语法筛选
|
||||
:param filter_loc: 用于筛选元素的查询语法
|
||||
"""返回文档中当前元素前面符合条件的元素或节点组成的列表,可用查询语法筛选
|
||||
查找范围不限同级元素,而是整个DOM文档
|
||||
:param filter_loc: 用于筛选的查询语法
|
||||
:return: 本元素前面的元素或节点组成的列表
|
||||
"""
|
||||
loc = get_loc(filter_loc, True)
|
||||
@ -988,8 +1059,9 @@ class ChromiumShadowRoot(BaseElement):
|
||||
return self.parent_ele._ele(xpath, single=False, relative=True)
|
||||
|
||||
def afters(self, filter_loc=''):
|
||||
"""返回前面全部兄弟元素或节点组成的列表,可用查询语法筛选
|
||||
:param filter_loc: 用于筛选元素的查询语法
|
||||
"""返回文档中当前元素后面符合条件的元素或节点组成的列表,可用查询语法筛选
|
||||
查找范围不限同级元素,而是整个DOM文档
|
||||
:param filter_loc: 用于筛选的查询语法
|
||||
:return: 本元素后面的元素或节点组成的列表
|
||||
"""
|
||||
eles1 = self.nexts(filter_loc)
|
||||
|
@ -96,41 +96,50 @@ class ChromiumElement(DrissionElement):
|
||||
|
||||
def parent(self, level_or_loc: Union[tuple, str, int] = 1) -> Union[ChromiumElement, None]: ...
|
||||
|
||||
def prev(self,
|
||||
filter_loc: Union[tuple, str] = '',
|
||||
index: int = 1,
|
||||
timeout: float = 0) -> Union[ChromiumElement, str, None]: ...
|
||||
|
||||
def next(self,
|
||||
filter_loc: Union[tuple, str] = '',
|
||||
index: int = 1,
|
||||
timeout: float = 0) -> Union[ChromiumElement, str, None]: ...
|
||||
|
||||
def before(self,
|
||||
filter_loc: Union[tuple, str] = '',
|
||||
index: int = 1,
|
||||
timeout: float = None) -> Union[ChromiumElement, str, None]: ...
|
||||
|
||||
def after(self,
|
||||
filter_loc: Union[tuple, str] = '',
|
||||
def child(self, filter_loc: Union[tuple, str] = '',
|
||||
index: int = 1,
|
||||
timeout: float = None) -> Union[ChromiumElement, str, None]: ...
|
||||
timeout: float = 0,
|
||||
ele_only: bool = True) -> Union[ChromiumElement, str, None]: ...
|
||||
|
||||
def prevs(self,
|
||||
filter_loc: Union[tuple, str] = '',
|
||||
timeout: float = 0) -> List[Union[ChromiumElement, str]]: ...
|
||||
def prev(self, filter_loc: Union[tuple, str] = '',
|
||||
index: int = 1,
|
||||
timeout: float = 0,
|
||||
ele_only: bool = True) -> Union[ChromiumElement, str, None]: ...
|
||||
|
||||
def nexts(self,
|
||||
filter_loc: Union[tuple, str] = '',
|
||||
timeout: float = 0) -> List[Union[ChromiumElement, str]]: ...
|
||||
def next(self, filter_loc: Union[tuple, str] = '',
|
||||
index: int = 1,
|
||||
timeout: float = 0,
|
||||
ele_only: bool = True) -> Union[ChromiumElement, str, None]: ...
|
||||
|
||||
def befores(self,
|
||||
filter_loc: Union[tuple, str] = '',
|
||||
timeout: float = None) -> List[Union[ChromiumElement, str]]: ...
|
||||
def before(self, filter_loc: Union[tuple, str] = '',
|
||||
index: int = 1,
|
||||
timeout: float = None,
|
||||
ele_only: bool = True) -> Union[ChromiumElement, str, None]: ...
|
||||
|
||||
def afters(self,
|
||||
filter_loc: Union[tuple, str] = '',
|
||||
timeout: float = None) -> List[Union[ChromiumElement, str]]: ...
|
||||
def after(self, filter_loc: Union[tuple, str] = '',
|
||||
index: int = 1,
|
||||
timeout: float = None,
|
||||
ele_only: bool = True) -> Union[ChromiumElement, str, None]: ...
|
||||
|
||||
def children(self, filter_loc: Union[tuple, str] = '',
|
||||
timeout: float = 0,
|
||||
ele_only: bool = True) -> List[Union[ChromiumElement, str]]: ...
|
||||
|
||||
def prevs(self, filter_loc: Union[tuple, str] = '',
|
||||
timeout: float = 0,
|
||||
ele_only: bool = True) -> List[Union[ChromiumElement, str]]: ...
|
||||
|
||||
def nexts(self, filter_loc: Union[tuple, str] = '',
|
||||
timeout: float = 0,
|
||||
ele_only: bool = True) -> List[Union[ChromiumElement, str]]: ...
|
||||
|
||||
def befores(self, filter_loc: Union[tuple, str] = '',
|
||||
timeout: float = None,
|
||||
ele_only: bool = True) -> List[Union[ChromiumElement, str]]: ...
|
||||
|
||||
def afters(self, filter_loc: Union[tuple, str] = '',
|
||||
timeout: float = None,
|
||||
ele_only: bool = True) -> List[Union[ChromiumElement, str]]: ...
|
||||
|
||||
@property
|
||||
def wait(self) -> ChromiumElementWaiter: ...
|
||||
@ -261,18 +270,20 @@ class ChromiumShadowRoot(BaseElement):
|
||||
|
||||
def parent(self, level_or_loc: Union[str, int] = 1) -> ChromiumElement: ...
|
||||
|
||||
def next(self,
|
||||
filter_loc: Union[tuple, str] = '',
|
||||
def child(self, filter_loc: Union[tuple, str] = '',
|
||||
index: int = 1) -> Union[ChromiumElement, str, None]: ...
|
||||
|
||||
def next(self, filter_loc: Union[tuple, str] = '',
|
||||
index: int = 1) -> Union[ChromiumElement, str, None]: ...
|
||||
|
||||
def before(self,
|
||||
filter_loc: Union[tuple, str] = '',
|
||||
def before(self, filter_loc: Union[tuple, str] = '',
|
||||
index: int = 1) -> Union[ChromiumElement, str, None]: ...
|
||||
|
||||
def after(self,
|
||||
filter_loc: Union[tuple, str] = '',
|
||||
def after(self, filter_loc: Union[tuple, str] = '',
|
||||
index: int = 1) -> Union[ChromiumElement, str, None]: ...
|
||||
|
||||
def children(self, filter_loc: Union[tuple, str] = '') -> List[Union[ChromiumElement, str]]: ...
|
||||
|
||||
def nexts(self, filter_loc: Union[tuple, str] = '') -> List[Union[ChromiumElement, str]]: ...
|
||||
|
||||
def befores(self, filter_loc: Union[tuple, str] = '') -> List[Union[ChromiumElement, str]]: ...
|
||||
@ -293,8 +304,8 @@ class ChromiumShadowRoot(BaseElement):
|
||||
|
||||
def _find_elements(self, loc_or_str: Union[Tuple[str, str], str], timeout: float = None,
|
||||
single: bool = True, relative: bool = False, raise_err: bool = None) \
|
||||
-> Union[
|
||||
ChromiumElement, ChromiumFrame, NoneElement, str, List[Union[ChromiumElement, ChromiumFrame, str]]]: ...
|
||||
-> Union[ChromiumElement, ChromiumFrame, NoneElement, str, List[Union[ChromiumElement,
|
||||
ChromiumFrame, str]]]: ...
|
||||
|
||||
def _get_node_id(self, obj_id: str) -> str: ...
|
||||
|
||||
@ -343,8 +354,8 @@ def find_by_css(ele: ChromiumElement,
|
||||
timeout: float) -> Union[ChromiumElement, List[ChromiumElement], NoneElement]: ...
|
||||
|
||||
|
||||
def make_chromium_ele(page: ChromiumBase, node_id: str = ..., obj_id: str = ...) -> Union[
|
||||
ChromiumElement, ChromiumFrame]: ...
|
||||
def make_chromium_ele(page: ChromiumBase, node_id: str = ..., obj_id: str = ...) \
|
||||
-> Union[ChromiumElement, ChromiumFrame]: ...
|
||||
|
||||
|
||||
def make_js_for_find_ele_by_xpath(xpath: str, type_txt: str, node_txt: str) -> str: ...
|
||||
|
@ -338,81 +338,93 @@ class ChromiumFrame(ChromiumBase):
|
||||
self._check_ok()
|
||||
return self.frame_ele.parent(level_or_loc)
|
||||
|
||||
def prev(self, filter_loc='', index=1, timeout=0):
|
||||
"""返回前面的一个兄弟元素,可用查询语法筛选,可指定返回筛选结果的第几个
|
||||
:param filter_loc: 用于筛选元素的查询语法
|
||||
:param index: 前面第几个查询结果元素
|
||||
:param timeout: 查找元素的超时时间
|
||||
:return: 兄弟元素
|
||||
def prev(self, filter_loc='', index=1, timeout=0, ele_only=True):
|
||||
"""返回当前元素前面一个符合条件的同级元素,可用查询语法筛选,可指定返回筛选结果的第几个
|
||||
:param filter_loc: 用于筛选的查询语法
|
||||
:param index: 前面第几个查询结果,1开始
|
||||
:param timeout: 查找节点的超时时间
|
||||
:param ele_only: 是否只获取元素,为False时把文本、注释节点也纳入
|
||||
:return: 同级元素或节点
|
||||
"""
|
||||
self._check_ok()
|
||||
return self.frame_ele.prev(filter_loc, index, timeout)
|
||||
return self.frame_ele.prev(filter_loc, index, timeout, ele_only=ele_only)
|
||||
|
||||
def next(self, filter_loc='', index=1, timeout=0):
|
||||
"""返回后面的一个兄弟元素,可用查询语法筛选,可指定返回筛选结果的第几个
|
||||
:param filter_loc: 用于筛选元素的查询语法
|
||||
:param index: 后面第几个查询结果元素
|
||||
:param timeout: 查找元素的超时时间
|
||||
:return: 兄弟元素
|
||||
def next(self, filter_loc='', index=1, timeout=0, ele_only=True):
|
||||
"""返回当前元素后面一个符合条件的同级元素,可用查询语法筛选,可指定返回筛选结果的第几个
|
||||
:param filter_loc: 用于筛选的查询语法
|
||||
:param index: 后面第几个查询结果,1开始
|
||||
:param timeout: 查找节点的超时时间
|
||||
:param ele_only: 是否只获取元素,为False时把文本、注释节点也纳入
|
||||
:return: 同级元素或节点
|
||||
"""
|
||||
self._check_ok()
|
||||
return self.frame_ele.next(filter_loc, index, timeout)
|
||||
return self.frame_ele.next(filter_loc, index, timeout, ele_only=ele_only)
|
||||
|
||||
def before(self, filter_loc='', index=1, timeout=None):
|
||||
"""返回当前元素前面的一个元素,可指定筛选条件和第几个。查找范围不限兄弟元素,而是整个DOM文档
|
||||
:param filter_loc: 用于筛选元素的查询语法
|
||||
:param index: 前面第几个查询结果元素
|
||||
:param timeout: 查找元素的超时时间
|
||||
def before(self, filter_loc='', index=1, timeout=None, ele_only=True):
|
||||
"""返回文档中当前元素前面符合条件的第一个元素,可用查询语法筛选,可指定返回筛选结果的第几个
|
||||
查找范围不限同级元素,而是整个DOM文档
|
||||
:param filter_loc: 用于筛选的查询语法
|
||||
:param index: 前面第几个查询结果,1开始
|
||||
:param timeout: 查找节点的超时时间
|
||||
:param ele_only: 是否只获取元素,为False时把文本、注释节点也纳入
|
||||
:return: 本元素前面的某个元素或节点
|
||||
"""
|
||||
self._check_ok()
|
||||
return self.frame_ele.before(filter_loc, index, timeout)
|
||||
return self.frame_ele.before(filter_loc, index, timeout, ele_only=ele_only)
|
||||
|
||||
def after(self, filter_loc='', index=1, timeout=None):
|
||||
"""返回当前元素后面的一个元素,可指定筛选条件和第几个。查找范围不限兄弟元素,而是整个DOM文档
|
||||
:param filter_loc: 用于筛选元素的查询语法
|
||||
:param index: 后面第几个查询结果元素
|
||||
:param timeout: 查找元素的超时时间
|
||||
def after(self, filter_loc='', index=1, timeout=None, ele_only=True):
|
||||
"""返回文档中此当前元素后面符合条件的第一个元素,可用查询语法筛选,可指定返回筛选结果的第几个
|
||||
查找范围不限同级元素,而是整个DOM文档
|
||||
:param filter_loc: 用于筛选的查询语法
|
||||
:param index: 后面第几个查询结果,1开始
|
||||
:param timeout: 查找节点的超时时间
|
||||
:param ele_only: 是否只获取元素,为False时把文本、注释节点也纳入
|
||||
:return: 本元素后面的某个元素或节点
|
||||
"""
|
||||
self._check_ok()
|
||||
return self.frame_ele.after(filter_loc, index, timeout)
|
||||
return self.frame_ele.after(filter_loc, index, timeout, ele_only=ele_only)
|
||||
|
||||
def prevs(self, filter_loc='', timeout=0):
|
||||
"""返回前面全部兄弟元素或节点组成的列表,可用查询语法筛选
|
||||
:param filter_loc: 用于筛选元素的查询语法
|
||||
:param timeout: 查找元素的超时时间
|
||||
:return: 兄弟元素或节点文本组成的列表
|
||||
def prevs(self, filter_loc='', timeout=0, ele_only=True):
|
||||
"""返回当前元素前面符合条件的同级元素或节点组成的列表,可用查询语法筛选
|
||||
:param filter_loc: 用于筛选的查询语法
|
||||
:param timeout: 查找节点的超时时间
|
||||
:param ele_only: 是否只获取元素,为False时把文本、注释节点也纳入
|
||||
:return: 同级元素或节点文本组成的列表
|
||||
"""
|
||||
self._check_ok()
|
||||
return self.frame_ele.prevs(filter_loc, timeout)
|
||||
return self.frame_ele.prevs(filter_loc, timeout, ele_only=ele_only)
|
||||
|
||||
def nexts(self, filter_loc='', timeout=0):
|
||||
"""返回后面全部兄弟元素或节点组成的列表,可用查询语法筛选
|
||||
:param filter_loc: 用于筛选元素的查询语法
|
||||
:param timeout: 查找元素的超时时间
|
||||
:return: 兄弟元素或节点文本组成的列表
|
||||
def nexts(self, filter_loc='', timeout=0, ele_only=True):
|
||||
"""返回当前元素后面符合条件的同级元素或节点组成的列表,可用查询语法筛选
|
||||
:param filter_loc: 用于筛选的查询语法
|
||||
:param timeout: 查找节点的超时时间
|
||||
:param ele_only: 是否只获取元素,为False时把文本、注释节点也纳入
|
||||
:return: 同级元素或节点文本组成的列表
|
||||
"""
|
||||
self._check_ok()
|
||||
return self.frame_ele.nexts(filter_loc, timeout)
|
||||
return self.frame_ele.nexts(filter_loc, timeout, ele_only=ele_only)
|
||||
|
||||
def befores(self, filter_loc='', timeout=None):
|
||||
"""返回当前元素后面符合条件的全部兄弟元素或节点组成的列表,可用查询语法筛选。查找范围不限兄弟元素,而是整个DOM文档
|
||||
:param filter_loc: 用于筛选元素的查询语法
|
||||
:param timeout: 查找元素的超时时间
|
||||
def befores(self, filter_loc='', timeout=None, ele_only=True):
|
||||
"""返回文档中当前元素前面符合条件的元素或节点组成的列表,可用查询语法筛选
|
||||
查找范围不限同级元素,而是整个DOM文档
|
||||
:param filter_loc: 用于筛选的查询语法
|
||||
:param timeout: 查找节点的超时时间
|
||||
:param ele_only: 是否只获取元素,为False时把文本、注释节点也纳入
|
||||
:return: 本元素前面的元素或节点组成的列表
|
||||
"""
|
||||
self._check_ok()
|
||||
return self.frame_ele.befores(filter_loc, timeout)
|
||||
return self.frame_ele.befores(filter_loc, timeout, ele_only=ele_only)
|
||||
|
||||
def afters(self, filter_loc='', timeout=None):
|
||||
"""返回当前元素后面符合条件的全部兄弟元素或节点组成的列表,可用查询语法筛选。查找范围不限兄弟元素,而是整个DOM文档
|
||||
:param filter_loc: 用于筛选元素的查询语法
|
||||
:param timeout: 查找元素的超时时间
|
||||
def afters(self, filter_loc='', timeout=None, ele_only=True):
|
||||
"""返回文档中当前元素后面符合条件的元素或节点组成的列表,可用查询语法筛选
|
||||
查找范围不限同级元素,而是整个DOM文档
|
||||
:param filter_loc: 用于筛选的查询语法
|
||||
:param timeout: 查找节点的超时时间
|
||||
:param ele_only: 是否只获取元素,为False时把文本、注释节点也纳入
|
||||
:return: 本元素前面的元素或节点组成的列表
|
||||
"""
|
||||
self._check_ok()
|
||||
return self.frame_ele.afters(filter_loc, timeout)
|
||||
return self.frame_ele.afters(filter_loc, timeout, ele_only=ele_only)
|
||||
|
||||
def get_screenshot(self, path=None, as_bytes=None, as_base64=None):
|
||||
"""对页面进行截图,可对整个网页、可见网页、指定范围截图。对可视范围外截图需要90以上版本浏览器支持
|
||||
|
@ -115,41 +115,41 @@ class ChromiumFrame(ChromiumBase):
|
||||
|
||||
def parent(self, level_or_loc: Union[tuple, str, int] = 1) -> Union[ChromiumElement, None]: ...
|
||||
|
||||
def prev(self,
|
||||
filter_loc: Union[tuple, str] = '',
|
||||
def prev(self, filter_loc: Union[tuple, str] = '',
|
||||
index: int = 1,
|
||||
timeout: float = 0) -> Union[ChromiumElement, ChromiumFrame, str, None]: ...
|
||||
timeout: float = 0,
|
||||
ele_only: bool = True) -> Union[ChromiumElement, ChromiumFrame, str, None]: ...
|
||||
|
||||
def next(self,
|
||||
filter_loc: Union[tuple, str] = '',
|
||||
def next(self, filter_loc: Union[tuple, str] = '',
|
||||
index: int = 1,
|
||||
timeout: float = 0) -> Union[ChromiumElement, ChromiumFrame, str, None]: ...
|
||||
timeout: float = 0,
|
||||
ele_only: bool = True) -> Union[ChromiumElement, ChromiumFrame, str, None]: ...
|
||||
|
||||
def before(self,
|
||||
filter_loc: Union[tuple, str] = '',
|
||||
def before(self, filter_loc: Union[tuple, str] = '',
|
||||
index: int = 1,
|
||||
timeout: float = None) -> Union[ChromiumElement, ChromiumFrame, str, None]: ...
|
||||
timeout: float = None,
|
||||
ele_only: bool = True) -> Union[ChromiumElement, ChromiumFrame, str, None]: ...
|
||||
|
||||
def after(self,
|
||||
filter_loc: Union[tuple, str] = '',
|
||||
def after(self, filter_loc: Union[tuple, str] = '',
|
||||
index: int = 1,
|
||||
timeout: float = None) -> Union[ChromiumElement, ChromiumFrame, str, None]: ...
|
||||
timeout: float = None,
|
||||
ele_only: bool = True) -> Union[ChromiumElement, ChromiumFrame, str, None]: ...
|
||||
|
||||
def prevs(self,
|
||||
filter_loc: Union[tuple, str] = '',
|
||||
timeout: float = 0) -> List[Union[ChromiumElement, ChromiumFrame, str]]: ...
|
||||
def prevs(self, filter_loc: Union[tuple, str] = '',
|
||||
timeout: float = 0,
|
||||
ele_only: bool = True) -> List[Union[ChromiumElement, ChromiumFrame, str]]: ...
|
||||
|
||||
def nexts(self,
|
||||
filter_loc: Union[tuple, str] = '',
|
||||
timeout: float = 0) -> List[Union[ChromiumElement, ChromiumFrame, str]]: ...
|
||||
def nexts(self, filter_loc: Union[tuple, str] = '',
|
||||
timeout: float = 0,
|
||||
ele_only: bool = True) -> List[Union[ChromiumElement, ChromiumFrame, str]]: ...
|
||||
|
||||
def befores(self,
|
||||
filter_loc: Union[tuple, str] = ...,
|
||||
timeout: float = ...) -> List[Union[ChromiumElement, ChromiumFrame, str]]: ...
|
||||
def befores(self, filter_loc: Union[tuple, str] = '',
|
||||
timeout: float = None,
|
||||
ele_only: bool = True) -> List[Union[ChromiumElement, ChromiumFrame, str]]: ...
|
||||
|
||||
def afters(self,
|
||||
filter_loc: Union[tuple, str] = ...,
|
||||
timeout: float = ...) -> List[Union[ChromiumElement, ChromiumFrame, str]]: ...
|
||||
def afters(self, filter_loc: Union[tuple, str] = '',
|
||||
timeout: float = None,
|
||||
ele_only: bool = True) -> List[Union[ChromiumElement, ChromiumFrame, str]]: ...
|
||||
|
||||
def get_screenshot(self, path: [str, Path] = None,
|
||||
as_bytes: [bool, str] = None,
|
||||
|
@ -339,7 +339,10 @@ def get_chrome_path(ini_path=None,
|
||||
|
||||
# -----------从系统变量中获取--------------
|
||||
if from_system_path:
|
||||
paths = popen('set path').read().encode('gbk').decode('utf-8').lower()
|
||||
try:
|
||||
paths = popen('set path').read().lower()
|
||||
except:
|
||||
return None
|
||||
r = search(r'[^;]*chrome[^;]*', paths)
|
||||
|
||||
if r:
|
||||
|
@ -129,9 +129,9 @@ class DrissionElement(BaseElement):
|
||||
|
||||
def prev(self, index=1, filter_loc='', timeout=0):
|
||||
"""返回前面的一个兄弟元素,可用查询语法筛选,可指定返回筛选结果的第几个
|
||||
:param index: 前面第几个查询结果元素
|
||||
:param filter_loc: 用于筛选元素的查询语法
|
||||
:param timeout: 查找元素的超时时间
|
||||
:param index: 前面第几个查询结果
|
||||
:param filter_loc: 用于筛选的查询语法
|
||||
:param timeout: 查找节点的超时时间
|
||||
:return: 兄弟元素
|
||||
"""
|
||||
nodes = self._get_brothers(index, filter_loc, 'preceding', timeout=timeout)
|
||||
@ -139,9 +139,9 @@ class DrissionElement(BaseElement):
|
||||
|
||||
def next(self, index=1, filter_loc='', timeout=0):
|
||||
"""返回后面的一个兄弟元素,可用查询语法筛选,可指定返回筛选结果的第几个
|
||||
:param index: 后面第几个查询结果元素
|
||||
:param filter_loc: 用于筛选元素的查询语法
|
||||
:param timeout: 查找元素的超时时间
|
||||
:param index: 后面第几个查询结果
|
||||
:param filter_loc: 用于筛选的查询语法
|
||||
:param timeout: 查找节点的超时时间
|
||||
:return: 兄弟元素
|
||||
"""
|
||||
nodes = self._get_brothers(index, filter_loc, 'following', timeout=timeout)
|
||||
@ -149,9 +149,9 @@ class DrissionElement(BaseElement):
|
||||
|
||||
def before(self, index=1, filter_loc='', timeout=None):
|
||||
"""返回前面的一个兄弟元素,可用查询语法筛选,可指定返回筛选结果的第几个
|
||||
:param index: 前面第几个查询结果元素
|
||||
:param filter_loc: 用于筛选元素的查询语法
|
||||
:param timeout: 查找元素的超时时间
|
||||
:param index: 前面第几个查询结果
|
||||
:param filter_loc: 用于筛选的查询语法
|
||||
:param timeout: 查找节点的超时时间
|
||||
:return: 本元素前面的某个元素或节点
|
||||
"""
|
||||
nodes = self._get_brothers(index, filter_loc, 'preceding', False, timeout=timeout)
|
||||
@ -159,9 +159,9 @@ class DrissionElement(BaseElement):
|
||||
|
||||
def after(self, index=1, filter_loc='', timeout=None):
|
||||
"""返回后面的一个兄弟元素,可用查询语法筛选,可指定返回筛选结果的第几个
|
||||
:param index: 后面第几个查询结果元素
|
||||
:param filter_loc: 用于筛选元素的查询语法
|
||||
:param timeout: 查找元素的超时时间
|
||||
:param index: 后面第几个查询结果
|
||||
:param filter_loc: 用于筛选的查询语法
|
||||
:param timeout: 查找节点的超时时间
|
||||
:return: 本元素后面的某个元素或节点
|
||||
"""
|
||||
nodes = self._get_brothers(index, filter_loc, 'following', False, timeout)
|
||||
@ -169,32 +169,32 @@ class DrissionElement(BaseElement):
|
||||
|
||||
def prevs(self, filter_loc='', timeout=0):
|
||||
"""返回前面全部兄弟元素或节点组成的列表,可用查询语法筛选
|
||||
:param filter_loc: 用于筛选元素的查询语法
|
||||
:param timeout: 查找元素的超时时间
|
||||
:param filter_loc: 用于筛选的查询语法
|
||||
:param timeout: 查找节点的超时时间
|
||||
:return: 兄弟元素或节点文本组成的列表
|
||||
"""
|
||||
return self._get_brothers(filter_loc=filter_loc, direction='preceding', timeout=timeout)
|
||||
|
||||
def nexts(self, filter_loc='', timeout=0):
|
||||
"""返回后面全部兄弟元素或节点组成的列表,可用查询语法筛选
|
||||
:param filter_loc: 用于筛选元素的查询语法
|
||||
:param timeout: 查找元素的超时时间
|
||||
:param filter_loc: 用于筛选的查询语法
|
||||
:param timeout: 查找节点的超时时间
|
||||
:return: 兄弟元素或节点文本组成的列表
|
||||
"""
|
||||
return self._get_brothers(filter_loc=filter_loc, direction='following', timeout=timeout)
|
||||
|
||||
def befores(self, filter_loc='', timeout=None):
|
||||
"""返回后面全部兄弟元素或节点组成的列表,可用查询语法筛选
|
||||
:param filter_loc: 用于筛选元素的查询语法
|
||||
:param timeout: 查找元素的超时时间
|
||||
:param filter_loc: 用于筛选的查询语法
|
||||
:param timeout: 查找节点的超时时间
|
||||
:return: 本元素前面的元素或节点组成的列表
|
||||
"""
|
||||
return self._get_brothers(filter_loc=filter_loc, direction='preceding', brother=False, timeout=timeout)
|
||||
|
||||
def afters(self, filter_loc='', timeout=None):
|
||||
"""返回前面全部兄弟元素或节点组成的列表,可用查询语法筛选
|
||||
:param filter_loc: 用于筛选元素的查询语法
|
||||
:param timeout: 查找元素的超时时间
|
||||
:param filter_loc: 用于筛选的查询语法
|
||||
:param timeout: 查找节点的超时时间
|
||||
:return: 本元素后面的元素或节点组成的列表
|
||||
"""
|
||||
return self._get_brothers(filter_loc=filter_loc, direction='following', brother=False, timeout=timeout)
|
||||
@ -202,7 +202,7 @@ class DrissionElement(BaseElement):
|
||||
def _get_brothers(self, index=None, filter_loc='', direction='following', brother=True, timeout=.5):
|
||||
"""按要求返回兄弟元素或节点组成的列表
|
||||
:param index: 获取第几个,该参数不为None时只获取该编号的元素
|
||||
:param filter_loc: 用于筛选元素的查询语法
|
||||
:param filter_loc: 用于筛选的查询语法
|
||||
:param direction: 'following' 或 'preceding',查找的方向
|
||||
:param brother: 查找范围,在同级查找还是整个dom前后查找
|
||||
:param timeout: 查找等待时间
|
||||
|
@ -255,9 +255,9 @@ class DriverElement(DrissionElement):
|
||||
|
||||
def prev(self, index=1, filter_loc='', timeout=0):
|
||||
"""返回前面的一个兄弟元素,可用查询语法筛选,可指定返回筛选结果的第几个
|
||||
:param index: 前面第几个查询结果元素
|
||||
:param filter_loc: 用于筛选元素的查询语法
|
||||
:param timeout: 查找元素的超时时间
|
||||
:param index: 前面第几个查询结果
|
||||
:param filter_loc: 用于筛选的查询语法
|
||||
:param timeout: 查找节点的超时时间
|
||||
:return: 兄弟元素
|
||||
"""
|
||||
index, filter_loc = _exchange_arguments(index, filter_loc)
|
||||
@ -265,9 +265,9 @@ class DriverElement(DrissionElement):
|
||||
|
||||
def next(self, index=1, filter_loc='', timeout=0):
|
||||
"""返回后面的一个兄弟元素,可用查询语法筛选,可指定返回筛选结果的第几个
|
||||
:param index: 后面第几个查询结果元素
|
||||
:param filter_loc: 用于筛选元素的查询语法
|
||||
:param timeout: 查找元素的超时时间
|
||||
:param index: 后面第几个查询结果
|
||||
:param filter_loc: 用于筛选的查询语法
|
||||
:param timeout: 查找节点的超时时间
|
||||
:return: 兄弟元素
|
||||
"""
|
||||
index, filter_loc = _exchange_arguments(index, filter_loc)
|
||||
@ -275,9 +275,9 @@ class DriverElement(DrissionElement):
|
||||
|
||||
def before(self, index=1, filter_loc='', timeout=None):
|
||||
"""返回当前元素前面的一个元素,可指定筛选条件和第几个。查找范围不限兄弟元,而是整个DOM文档
|
||||
:param index: 前面第几个查询结果元素
|
||||
:param filter_loc: 用于筛选元素的查询语法
|
||||
:param timeout: 查找元素的超时时间
|
||||
:param index: 前面第几个查询结果
|
||||
:param filter_loc: 用于筛选的查询语法
|
||||
:param timeout: 查找节点的超时时间
|
||||
:return: 本元素前面的某个元素或节点
|
||||
"""
|
||||
index, filter_loc = _exchange_arguments(index, filter_loc)
|
||||
@ -285,9 +285,9 @@ class DriverElement(DrissionElement):
|
||||
|
||||
def after(self, index=1, filter_loc='', timeout=None):
|
||||
"""返回当前元素后面的一个元素,可指定筛选条件和第几个。查找范围不限兄弟元,而是整个DOM文档
|
||||
:param index: 后面第几个查询结果元素
|
||||
:param filter_loc: 用于筛选元素的查询语法
|
||||
:param timeout: 查找元素的超时时间
|
||||
:param index: 后面第几个查询结果
|
||||
:param filter_loc: 用于筛选的查询语法
|
||||
:param timeout: 查找节点的超时时间
|
||||
:return: 本元素后面的某个元素或节点
|
||||
"""
|
||||
index, filter_loc = _exchange_arguments(index, filter_loc)
|
||||
@ -295,32 +295,32 @@ class DriverElement(DrissionElement):
|
||||
|
||||
def prevs(self, filter_loc='', timeout=0):
|
||||
"""返回前面全部兄弟元素或节点组成的列表,可用查询语法筛选
|
||||
:param filter_loc: 用于筛选元素的查询语法
|
||||
:param timeout: 查找元素的超时时间
|
||||
:param filter_loc: 用于筛选的查询语法
|
||||
:param timeout: 查找节点的超时时间
|
||||
:return: 兄弟元素或节点文本组成的列表
|
||||
"""
|
||||
return super().prevs(filter_loc, timeout)
|
||||
|
||||
def nexts(self, filter_loc='', timeout=0):
|
||||
"""返回后面全部兄弟元素或节点组成的列表,可用查询语法筛选
|
||||
:param filter_loc: 用于筛选元素的查询语法
|
||||
:param timeout: 查找元素的超时时间
|
||||
:param filter_loc: 用于筛选的查询语法
|
||||
:param timeout: 查找节点的超时时间
|
||||
:return: 兄弟元素或节点文本组成的列表
|
||||
"""
|
||||
return super().nexts(filter_loc, timeout)
|
||||
|
||||
def befores(self, filter_loc='', timeout=None):
|
||||
"""返回当前元素后面符合条件的全部兄弟元素或节点组成的列表,可用查询语法筛选。查找范围不限兄弟元,而是整个DOM文档
|
||||
:param filter_loc: 用于筛选元素的查询语法
|
||||
:param timeout: 查找元素的超时时间
|
||||
:param filter_loc: 用于筛选的查询语法
|
||||
:param timeout: 查找节点的超时时间
|
||||
:return: 本元素前面的元素或节点组成的列表
|
||||
"""
|
||||
return super().befores(filter_loc, timeout)
|
||||
|
||||
def afters(self, filter_loc='', timeout=None):
|
||||
"""返回当前元素前面符合条件的全部兄弟元素或节点组成的列表,可用查询语法筛选。查找范围不限兄弟元,而是整个DOM文档
|
||||
:param filter_loc: 用于筛选元素的查询语法
|
||||
:param timeout: 查找元素的超时时间
|
||||
:param filter_loc: 用于筛选的查询语法
|
||||
:param timeout: 查找节点的超时时间
|
||||
:return: 本元素后面的元素或节点组成的列表
|
||||
"""
|
||||
return super().afters(filter_loc, timeout)
|
||||
|
@ -83,68 +83,68 @@ class SessionElement(DrissionElement):
|
||||
|
||||
def prev(self, filter_loc='', index=1, timeout=None):
|
||||
"""返回前面的一个兄弟元素,可用查询语法筛选,可指定返回筛选结果的第几个
|
||||
:param filter_loc: 用于筛选元素的查询语法
|
||||
:param index: 前面第几个查询结果元素
|
||||
:param timeout: 查找元素的超时时间
|
||||
:param filter_loc: 用于筛选的查询语法
|
||||
:param index: 前面第几个查询结果
|
||||
:param timeout: 查找节点的超时时间
|
||||
:return: 兄弟元素
|
||||
"""
|
||||
return super().prev(index, filter_loc, timeout)
|
||||
|
||||
def next(self, filter_loc='', index=1, timeout=None):
|
||||
"""返回后面的一个兄弟元素,可用查询语法筛选,可指定返回筛选结果的第几个
|
||||
:param filter_loc: 用于筛选元素的查询语法
|
||||
:param index: 后面第几个查询结果元素
|
||||
:param timeout: 查找元素的超时时间
|
||||
:param filter_loc: 用于筛选的查询语法
|
||||
:param index: 后面第几个查询结果
|
||||
:param timeout: 查找节点的超时时间
|
||||
:return: 兄弟元素
|
||||
"""
|
||||
return super().next(index, filter_loc, timeout)
|
||||
|
||||
def before(self, filter_loc='', index=1, timeout=None):
|
||||
"""返回前面的一个兄弟元素,可用查询语法筛选,可指定返回筛选结果的第几个
|
||||
:param filter_loc: 用于筛选元素的查询语法
|
||||
:param index: 前面第几个查询结果元素
|
||||
:param timeout: 查找元素的超时时间
|
||||
:param filter_loc: 用于筛选的查询语法
|
||||
:param index: 前面第几个查询结果
|
||||
:param timeout: 查找节点的超时时间
|
||||
:return: 本元素前面的某个元素或节点
|
||||
"""
|
||||
return super().before(index, filter_loc, timeout)
|
||||
|
||||
def after(self, filter_loc='', index=1, timeout=None):
|
||||
"""返回后面的一个兄弟元素,可用查询语法筛选,可指定返回筛选结果的第几个
|
||||
:param filter_loc: 用于筛选元素的查询语法
|
||||
:param index: 后面第几个查询结果元素
|
||||
:param timeout: 查找元素的超时时间
|
||||
:param filter_loc: 用于筛选的查询语法
|
||||
:param index: 后面第几个查询结果
|
||||
:param timeout: 查找节点的超时时间
|
||||
:return: 本元素后面的某个元素或节点
|
||||
"""
|
||||
return super().after(index, filter_loc, timeout)
|
||||
|
||||
def prevs(self, filter_loc='', timeout=None):
|
||||
"""返回前面全部兄弟元素或节点组成的列表,可用查询语法筛选
|
||||
:param filter_loc: 用于筛选元素的查询语法
|
||||
:param timeout: 查找元素的超时时间
|
||||
:param filter_loc: 用于筛选的查询语法
|
||||
:param timeout: 查找节点的超时时间
|
||||
:return: 兄弟元素或节点文本组成的列表
|
||||
"""
|
||||
return super().prevs(filter_loc, timeout)
|
||||
|
||||
def nexts(self, filter_loc='', timeout=None):
|
||||
"""返回后面全部兄弟元素或节点组成的列表,可用查询语法筛选
|
||||
:param filter_loc: 用于筛选元素的查询语法
|
||||
:param timeout: 查找元素的超时时间
|
||||
:param filter_loc: 用于筛选的查询语法
|
||||
:param timeout: 查找节点的超时时间
|
||||
:return: 兄弟元素或节点文本组成的列表
|
||||
"""
|
||||
return super().nexts(filter_loc, timeout)
|
||||
|
||||
def befores(self, filter_loc='', timeout=None):
|
||||
"""返回后面全部兄弟元素或节点组成的列表,可用查询语法筛选
|
||||
:param filter_loc: 用于筛选元素的查询语法
|
||||
:param timeout: 查找元素的超时时间
|
||||
:param filter_loc: 用于筛选的查询语法
|
||||
:param timeout: 查找节点的超时时间
|
||||
:return: 本元素前面的元素或节点组成的列表
|
||||
"""
|
||||
return super().befores(filter_loc, timeout)
|
||||
|
||||
def afters(self, filter_loc='', timeout=None):
|
||||
"""返回前面全部兄弟元素或节点组成的列表,可用查询语法筛选
|
||||
:param filter_loc: 用于筛选元素的查询语法
|
||||
:param timeout: 查找元素的超时时间
|
||||
:param filter_loc: 用于筛选的查询语法
|
||||
:param timeout: 查找节点的超时时间
|
||||
:return: 本元素后面的元素或节点组成的列表
|
||||
"""
|
||||
return super().afters(filter_loc, timeout)
|
||||
|
@ -76,8 +76,8 @@ class ShadowRootElement(BaseElement):
|
||||
|
||||
def next(self, index=1, filter_loc=''):
|
||||
"""返回后面的一个兄弟元素,可用查询语法筛选,可指定返回筛选结果的第几个
|
||||
:param index: 第几个查询结果元素
|
||||
:param filter_loc: 用于筛选元素的查询语法
|
||||
:param index: 第几个查询结果
|
||||
:param filter_loc: 用于筛选的查询语法
|
||||
:return: DriverElement对象
|
||||
"""
|
||||
nodes = self.nexts(filter_loc=filter_loc)
|
||||
@ -85,8 +85,8 @@ class ShadowRootElement(BaseElement):
|
||||
|
||||
def before(self, index=1, filter_loc=''):
|
||||
"""返回前面的一个兄弟元素,可用查询语法筛选,可指定返回筛选结果的第几个
|
||||
:param index: 前面第几个查询结果元素
|
||||
:param filter_loc: 用于筛选元素的查询语法
|
||||
:param index: 前面第几个查询结果
|
||||
:param filter_loc: 用于筛选的查询语法
|
||||
:return: 本元素前面的某个元素或节点
|
||||
"""
|
||||
nodes = self.befores(filter_loc=filter_loc)
|
||||
@ -94,8 +94,8 @@ class ShadowRootElement(BaseElement):
|
||||
|
||||
def after(self, index=1, filter_loc=''):
|
||||
"""返回后面的一个兄弟元素,可用查询语法筛选,可指定返回筛选结果的第几个
|
||||
:param index: 后面第几个查询结果元素
|
||||
:param filter_loc: 用于筛选元素的查询语法
|
||||
:param index: 后面第几个查询结果
|
||||
:param filter_loc: 用于筛选的查询语法
|
||||
:return: 本元素后面的某个元素或节点
|
||||
"""
|
||||
nodes = self.afters(filter_loc=filter_loc)
|
||||
@ -103,7 +103,7 @@ class ShadowRootElement(BaseElement):
|
||||
|
||||
def nexts(self, filter_loc=''):
|
||||
"""返回后面所有兄弟元素或节点组成的列表
|
||||
:param filter_loc: 用于筛选元素的查询语法
|
||||
:param filter_loc: 用于筛选的查询语法
|
||||
:return: DriverElement对象组成的列表
|
||||
"""
|
||||
loc = get_loc(filter_loc, True)
|
||||
@ -116,7 +116,7 @@ class ShadowRootElement(BaseElement):
|
||||
|
||||
def befores(self, filter_loc=''):
|
||||
"""返回后面全部兄弟元素或节点组成的列表,可用查询语法筛选
|
||||
:param filter_loc: 用于筛选元素的查询语法
|
||||
:param filter_loc: 用于筛选的查询语法
|
||||
:return: 本元素前面的元素或节点组成的列表
|
||||
"""
|
||||
loc = get_loc(filter_loc, True)
|
||||
@ -129,7 +129,7 @@ class ShadowRootElement(BaseElement):
|
||||
|
||||
def afters(self, filter_loc=''):
|
||||
"""返回前面全部兄弟元素或节点组成的列表,可用查询语法筛选
|
||||
:param filter_loc: 用于筛选元素的查询语法
|
||||
:param filter_loc: 用于筛选的查询语法
|
||||
:return: 本元素后面的元素或节点组成的列表
|
||||
"""
|
||||
eles1 = self.nexts(filter_loc)
|
||||
|
@ -82,73 +82,104 @@ class SessionElement(DrissionElement):
|
||||
"""
|
||||
return super().parent(level_or_loc)
|
||||
|
||||
def prev(self, filter_loc='', index=1, timeout=None):
|
||||
"""返回前面的一个兄弟元素,可用查询语法筛选,可指定返回筛选结果的第几个
|
||||
:param filter_loc: 用于筛选元素的查询语法
|
||||
:param index: 前面第几个查询结果元素
|
||||
:param timeout: 查找元素的超时时间
|
||||
:return: 兄弟元素
|
||||
def child(self, filter_loc='', index=1, timeout=None, ele_only=True):
|
||||
"""返回当前元素的一个符合条件的直接子元素,可用查询语法筛选,可指定返回筛选结果的第几个
|
||||
:param filter_loc: 用于筛选的查询语法
|
||||
:param index: 第几个查询结果,1开始
|
||||
:param timeout: 此参数不起实际作用
|
||||
:param ele_only: 是否只获取元素,为False时把文本、注释节点也纳入
|
||||
:return: 直接子元素或节点文本
|
||||
"""
|
||||
return super().prev(index, filter_loc, timeout)
|
||||
return super().child(index, filter_loc, timeout, ele_only=ele_only)
|
||||
|
||||
def next(self, filter_loc='', index=1, timeout=None):
|
||||
"""返回后面的一个兄弟元素,可用查询语法筛选,可指定返回筛选结果的第几个
|
||||
:param filter_loc: 用于筛选元素的查询语法
|
||||
:param index: 后面第几个查询结果元素
|
||||
:param timeout: 查找元素的超时时间
|
||||
:return: 兄弟元素
|
||||
def prev(self, filter_loc='', index=1, timeout=None, ele_only=True):
|
||||
"""返回当前元素前面一个符合条件的同级元素,可用查询语法筛选,可指定返回筛选结果的第几个
|
||||
:param filter_loc: 用于筛选的查询语法
|
||||
:param index: 前面第几个查询结果,1开始
|
||||
:param timeout: 此参数不起实际作用
|
||||
:param ele_only: 是否只获取元素,为False时把文本、注释节点也纳入
|
||||
:return: 同级元素
|
||||
"""
|
||||
return super().next(index, filter_loc, timeout)
|
||||
return super().prev(index, filter_loc, timeout, ele_only=ele_only)
|
||||
|
||||
def before(self, filter_loc='', index=1, timeout=None):
|
||||
"""返回前面的一个兄弟元素,可用查询语法筛选,可指定返回筛选结果的第几个
|
||||
:param filter_loc: 用于筛选元素的查询语法
|
||||
:param index: 前面第几个查询结果元素
|
||||
:param timeout: 查找元素的超时时间
|
||||
def next(self, filter_loc='', index=1, timeout=None, ele_only=True):
|
||||
"""返回当前元素后面一个符合条件的同级元素,可用查询语法筛选,可指定返回筛选结果的第几个
|
||||
:param filter_loc: 用于筛选的查询语法
|
||||
:param index: 第几个查询结果,1开始
|
||||
:param timeout: 此参数不起实际作用
|
||||
:param ele_only: 是否只获取元素,为False时把文本、注释节点也纳入
|
||||
:return: 同级元素
|
||||
"""
|
||||
return super().next(index, filter_loc, timeout, ele_only=ele_only)
|
||||
|
||||
def before(self, filter_loc='', index=1, timeout=None, ele_only=True):
|
||||
"""返回文档中当前元素前面符合条件的第一个元素,可用查询语法筛选,可指定返回筛选结果的第几个
|
||||
查找范围不限同级元素,而是整个DOM文档
|
||||
:param filter_loc: 用于筛选的查询语法
|
||||
:param index: 前面第几个查询结果,1开始
|
||||
:param timeout: 此参数不起实际作用
|
||||
:param ele_only: 是否只获取元素,为False时把文本、注释节点也纳入
|
||||
:return: 本元素前面的某个元素或节点
|
||||
"""
|
||||
return super().before(index, filter_loc, timeout)
|
||||
return super().before(index, filter_loc, timeout, ele_only=ele_only)
|
||||
|
||||
def after(self, filter_loc='', index=1, timeout=None):
|
||||
"""返回后面的一个兄弟元素,可用查询语法筛选,可指定返回筛选结果的第几个
|
||||
:param filter_loc: 用于筛选元素的查询语法
|
||||
:param index: 后面第几个查询结果元素
|
||||
:param timeout: 查找元素的超时时间
|
||||
def after(self, filter_loc='', index=1, timeout=None, ele_only=True):
|
||||
"""返回文档中此当前元素后面符合条件的第一个元素,可用查询语法筛选,可指定返回筛选结果的第几个
|
||||
查找范围不限同级元素,而是整个DOM文档
|
||||
:param filter_loc: 用于筛选的查询语法
|
||||
:param index: 第几个查询结果,1开始
|
||||
:param timeout: 此参数不起实际作用
|
||||
:param ele_only: 是否只获取元素,为False时把文本、注释节点也纳入
|
||||
:return: 本元素后面的某个元素或节点
|
||||
"""
|
||||
return super().after(index, filter_loc, timeout)
|
||||
return super().after(index, filter_loc, timeout, ele_only=ele_only)
|
||||
|
||||
def prevs(self, filter_loc='', timeout=None):
|
||||
"""返回前面全部兄弟元素或节点组成的列表,可用查询语法筛选
|
||||
:param filter_loc: 用于筛选元素的查询语法
|
||||
:param timeout: 查找元素的超时时间
|
||||
:return: 兄弟元素或节点文本组成的列表
|
||||
def children(self, filter_loc='', timeout=0, ele_only=True):
|
||||
"""返回当前元素符合条件的直接子元素或节点组成的列表,可用查询语法筛选
|
||||
:param filter_loc: 用于筛选的查询语法
|
||||
:param timeout: 此参数不起实际作用
|
||||
:param ele_only: 是否只获取元素,为False时把文本、注释节点也纳入
|
||||
:return: 直接子元素或节点文本组成的列表
|
||||
"""
|
||||
return super().prevs(filter_loc, timeout)
|
||||
return super().children(filter_loc, timeout, ele_only=ele_only)
|
||||
|
||||
def nexts(self, filter_loc='', timeout=None):
|
||||
"""返回后面全部兄弟元素或节点组成的列表,可用查询语法筛选
|
||||
:param filter_loc: 用于筛选元素的查询语法
|
||||
:param timeout: 查找元素的超时时间
|
||||
:return: 兄弟元素或节点文本组成的列表
|
||||
def prevs(self, filter_loc='', timeout=None, ele_only=True):
|
||||
"""返回当前元素前面符合条件的同级元素或节点组成的列表,可用查询语法筛选
|
||||
:param filter_loc: 用于筛选的查询语法
|
||||
:param timeout: 此参数不起实际作用
|
||||
:param ele_only: 是否只获取元素,为False时把文本、注释节点也纳入
|
||||
:return: 同级元素或节点文本组成的列表
|
||||
"""
|
||||
return super().nexts(filter_loc, timeout)
|
||||
return super().prevs(filter_loc, timeout, ele_only=ele_only)
|
||||
|
||||
def befores(self, filter_loc='', timeout=None):
|
||||
"""返回后面全部兄弟元素或节点组成的列表,可用查询语法筛选
|
||||
:param filter_loc: 用于筛选元素的查询语法
|
||||
:param timeout: 查找元素的超时时间
|
||||
def nexts(self, filter_loc='', timeout=None, ele_only=True):
|
||||
"""返回当前元素后面符合条件的同级元素或节点组成的列表,可用查询语法筛选
|
||||
:param filter_loc: 用于筛选的查询语法
|
||||
:param timeout: 此参数不起实际作用
|
||||
:param ele_only: 是否只获取元素,为False时把文本、注释节点也纳入
|
||||
:return: 同级元素或节点文本组成的列表
|
||||
"""
|
||||
return super().nexts(filter_loc, timeout, ele_only=ele_only)
|
||||
|
||||
def befores(self, filter_loc='', timeout=None, ele_only=True):
|
||||
"""返回文档中当前元素前面符合条件的元素或节点组成的列表,可用查询语法筛选
|
||||
查找范围不限同级元素,而是整个DOM文档
|
||||
:param filter_loc: 用于筛选的查询语法
|
||||
:param timeout: 此参数不起实际作用
|
||||
:param ele_only: 是否只获取元素,为False时把文本、注释节点也纳入
|
||||
:return: 本元素前面的元素或节点组成的列表
|
||||
"""
|
||||
return super().befores(filter_loc, timeout)
|
||||
return super().befores(filter_loc, timeout, ele_only=ele_only)
|
||||
|
||||
def afters(self, filter_loc='', timeout=None):
|
||||
"""返回前面全部兄弟元素或节点组成的列表,可用查询语法筛选
|
||||
:param filter_loc: 用于筛选元素的查询语法
|
||||
:param timeout: 查找元素的超时时间
|
||||
def afters(self, filter_loc='', timeout=None, ele_only=True):
|
||||
"""返回文档中当前元素后面符合条件的元素或节点组成的列表,可用查询语法筛选
|
||||
查找范围不限同级元素,而是整个DOM文档
|
||||
:param filter_loc: 用于筛选的查询语法
|
||||
:param timeout: 此参数不起实际作用
|
||||
:param ele_only: 是否只获取元素,为False时把文本、注释节点也纳入
|
||||
:return: 本元素后面的元素或节点组成的列表
|
||||
"""
|
||||
return super().afters(filter_loc, timeout)
|
||||
return super().afters(filter_loc, timeout, ele_only=ele_only)
|
||||
|
||||
def attr(self, attr):
|
||||
"""返回attribute属性值
|
||||
|
@ -12,8 +12,8 @@ from .chromium_base import ChromiumBase
|
||||
from .chromium_element import ChromiumElement
|
||||
from .chromium_frame import ChromiumFrame
|
||||
from .commons.constants import NoneElement
|
||||
from .driver_element import DriverElement
|
||||
from .driver_page import DriverPage
|
||||
from mixpage.driver_element import DriverElement
|
||||
from mixpage.driver_page import DriverPage
|
||||
from .session_page import SessionPage
|
||||
|
||||
|
||||
@ -52,41 +52,50 @@ class SessionElement(DrissionElement):
|
||||
|
||||
def parent(self, level_or_loc: Union[tuple, str, int] = 1) -> Union['SessionElement', None]: ...
|
||||
|
||||
def prev(self,
|
||||
filter_loc: Union[tuple, str] = '',
|
||||
index: int = 1,
|
||||
timeout: float = None) -> Union['SessionElement', str, None]: ...
|
||||
|
||||
def next(self,
|
||||
filter_loc: Union[tuple, str] = '',
|
||||
index: int = 1,
|
||||
timeout: float = None) -> Union['SessionElement', str, None]: ...
|
||||
|
||||
def before(self,
|
||||
filter_loc: Union[tuple, str] = '',
|
||||
index: int = 1,
|
||||
timeout: float = None) -> Union['SessionElement', str, None]: ...
|
||||
|
||||
def after(self,
|
||||
filter_loc: Union[tuple, str] = '',
|
||||
def child(self, filter_loc: Union[tuple, str] = '',
|
||||
index: int = 1,
|
||||
timeout: float = None) -> Union['SessionElement', str, None]: ...
|
||||
timeout: float = None,
|
||||
ele_only: bool = True) -> Union['SessionElement', str, None]: ...
|
||||
|
||||
def prevs(self,
|
||||
filter_loc: Union[tuple, str] = '',
|
||||
timeout: float = None) -> List[Union['SessionElement', str]]: ...
|
||||
def prev(self, filter_loc: Union[tuple, str] = '',
|
||||
index: int = 1,
|
||||
timeout: float = None,
|
||||
ele_only: bool = True) -> Union['SessionElement', str, None]: ...
|
||||
|
||||
def nexts(self,
|
||||
filter_loc: Union[tuple, str] = '',
|
||||
timeout: float = None) -> List[Union['SessionElement', str]]: ...
|
||||
def next(self, filter_loc: Union[tuple, str] = '',
|
||||
index: int = 1,
|
||||
timeout: float = None,
|
||||
ele_only: bool = True) -> Union['SessionElement', str, None]: ...
|
||||
|
||||
def befores(self,
|
||||
filter_loc: Union[tuple, str] = '',
|
||||
timeout: float = None) -> List[Union['SessionElement', str]]: ...
|
||||
def before(self, filter_loc: Union[tuple, str] = '',
|
||||
index: int = 1,
|
||||
timeout: float = None,
|
||||
ele_only: bool = True) -> Union['SessionElement', str, None]: ...
|
||||
|
||||
def afters(self,
|
||||
filter_loc: Union[tuple, str] = '',
|
||||
timeout: float = None) -> List[Union['SessionElement', str]]: ...
|
||||
def after(self, filter_loc: Union[tuple, str] = '',
|
||||
index: int = 1,
|
||||
timeout: float = None,
|
||||
ele_only: bool = True) -> Union['SessionElement', str, None]: ...
|
||||
|
||||
def children(self, filter_loc: Union[tuple, str] = '',
|
||||
timeout: float = None,
|
||||
ele_only: bool = True) -> List[Union['SessionElement', str]]: ...
|
||||
|
||||
def prevs(self, filter_loc: Union[tuple, str] = '',
|
||||
timeout: float = None,
|
||||
ele_only: bool = True) -> List[Union['SessionElement', str]]: ...
|
||||
|
||||
def nexts(self, filter_loc: Union[tuple, str] = '',
|
||||
timeout: float = None,
|
||||
ele_only: bool = True) -> List[Union['SessionElement', str]]: ...
|
||||
|
||||
def befores(self, filter_loc: Union[tuple, str] = '',
|
||||
timeout: float = None,
|
||||
ele_only: bool = True) -> List[Union['SessionElement', str]]: ...
|
||||
|
||||
def afters(self, filter_loc: Union[tuple, str] = '',
|
||||
timeout: float = None,
|
||||
ele_only: bool = True) -> List[Union['SessionElement', str]]: ...
|
||||
|
||||
def attr(self, attr: str) -> Union[str, None]: ...
|
||||
|
||||
@ -105,18 +114,18 @@ class SessionElement(DrissionElement):
|
||||
loc_or_str: Union[Tuple[str, str], str]) -> List[Union['SessionElement', str]]: ...
|
||||
|
||||
def _find_elements(self,
|
||||
loc_or_str: Union[Tuple[str, str], str],
|
||||
timeout: float = None,
|
||||
single: bool = True,
|
||||
relative: bool = False,
|
||||
raise_err: bool = None) \
|
||||
loc_or_str: Union[Tuple[str, str], str],
|
||||
timeout: float = None,
|
||||
single: bool = True,
|
||||
relative: bool = False,
|
||||
raise_err: bool = None) \
|
||||
-> Union['SessionElement', str, NoneElement, List[Union['SessionElement', str]]]: ...
|
||||
|
||||
def _get_ele_path(self, mode: str) -> str: ...
|
||||
|
||||
|
||||
def make_session_ele(html_or_ele: Union[str, SessionElement, SessionPage, ChromiumElement, DriverElement, BaseElement,
|
||||
ChromiumFrame, ChromiumBase, DriverPage],
|
||||
ChromiumFrame, ChromiumBase, DriverPage],
|
||||
loc: Union[str, Tuple[str, str]] = None,
|
||||
single: bool = True) -> Union[
|
||||
SessionElement, str, NoneElement, List[Union[SessionElement, str]]]: ...
|
||||
|
Loading…
x
Reference in New Issue
Block a user