mirror of
https://gitee.com/g1879/DrissionPage.git
synced 2024-12-10 04:00:23 +08:00
texts属性,未完成
This commit is contained in:
parent
9a6afd6a07
commit
c1f3f51a14
@ -61,9 +61,11 @@ class DriverElement(DrissionElement):
|
|||||||
"""返回元素内所有文本"""
|
"""返回元素内所有文本"""
|
||||||
return unescape(self.attr('innerText')).replace('\xa0', ' ')
|
return unescape(self.attr('innerText')).replace('\xa0', ' ')
|
||||||
|
|
||||||
@property
|
def texts(self, text_node_only: bool = False) -> List[str]:
|
||||||
def texts(self) -> List[str]:
|
|
||||||
"""返回元素内文本节点列表"""
|
"""返回元素内文本节点列表"""
|
||||||
|
s = '' if text_node_only else '''else if(childs[i].nodeType === Node.ELEMENT_NODE){
|
||||||
|
texts.push(childs[i].innerText)
|
||||||
|
}'''
|
||||||
js = '''
|
js = '''
|
||||||
function e(el) {
|
function e(el) {
|
||||||
if (!(el instanceof Element)) return;
|
if (!(el instanceof Element)) return;
|
||||||
@ -73,7 +75,7 @@ class DriverElement(DrissionElement):
|
|||||||
for(var i = 0; i <childs.length ; i++) {
|
for(var i = 0; i <childs.length ; i++) {
|
||||||
if(childs[i].nodeType === Node.TEXT_NODE){
|
if(childs[i].nodeType === Node.TEXT_NODE){
|
||||||
texts.push(childs[i].nodeValue)
|
texts.push(childs[i].nodeValue)
|
||||||
}
|
}''' + s + '''
|
||||||
}
|
}
|
||||||
return texts;
|
return texts;
|
||||||
}
|
}
|
||||||
|
@ -36,8 +36,7 @@ class SessionElement(DrissionElement):
|
|||||||
"""返回元素内所有文本"""
|
"""返回元素内所有文本"""
|
||||||
return unescape(self._inner_ele.text).replace('\xa0', ' ')
|
return unescape(self._inner_ele.text).replace('\xa0', ' ')
|
||||||
|
|
||||||
@property
|
def texts(self, text_node_only: bool = False) -> List[str]:
|
||||||
def texts(self) -> List[str]:
|
|
||||||
# TODO: 待补充
|
# TODO: 待补充
|
||||||
return []
|
return []
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user