[英]in lxml.html how do i grab the text, children and content of children of a node?
I'm using python's lxml.html. 我正在使用python的lxml.html。 I have an xpath expression which grabs the text of a node but what I need is all the text including the tags of the children tags and their content. 我有一个xpath表达式,它可以获取节点的文本,但我需要的是所有文本,包括子标签和其内容的标签。 How do I achieve this? 我该如何实现?
Element
的text_content方法返回元素的文本,包括没有标记的子元素的文本内容。
I am not sure what tags you are using; 我不确定您使用的是什么标签; therefore, I make up sth. 因此,我弥补了。
You can try sth like: 您可以尝试:
result = lxml.html.parse(url).xpath("//tr/td/a/text()")
//tr means Selects nodes in the document from the current node that match the selection no matter where they are. // tr表示无论在何处,都从当前节点中选择与选择匹配的节点。
You can use this ('//') expression to grap the tags of the children tags. 您可以使用此('//')表达式来掌握children标签的标签。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.