mirror of
https://gitee.com/g1879/DrissionPage.git
synced 2024-12-05 05:28:43 +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', ' ')
|
||||
|
||||
@property
|
||||
def texts(self) -> List[str]:
|
||||
def texts(self, text_node_only: bool = False) -> List[str]:
|
||||
"""返回元素内文本节点列表"""
|
||||
s = '' if text_node_only else '''else if(childs[i].nodeType === Node.ELEMENT_NODE){
|
||||
texts.push(childs[i].innerText)
|
||||
}'''
|
||||
js = '''
|
||||
function e(el) {
|
||||
if (!(el instanceof Element)) return;
|
||||
@ -73,7 +75,7 @@ class DriverElement(DrissionElement):
|
||||
for(var i = 0; i <childs.length ; i++) {
|
||||
if(childs[i].nodeType === Node.TEXT_NODE){
|
||||
texts.push(childs[i].nodeValue)
|
||||
}
|
||||
}''' + s + '''
|
||||
}
|
||||
return texts;
|
||||
}
|
||||
|
@ -36,8 +36,7 @@ class SessionElement(DrissionElement):
|
||||
"""返回元素内所有文本"""
|
||||
return unescape(self._inner_ele.text).replace('\xa0', ' ')
|
||||
|
||||
@property
|
||||
def texts(self) -> List[str]:
|
||||
def texts(self, text_node_only: bool = False) -> List[str]:
|
||||
# TODO: 待补充
|
||||
return []
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user