简体   繁体   中英

in lxml.html how do i grab the text, children and content of children of a node?

I'm using python's 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. How do I achieve this?

Elementtext_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.

You can use this ('//') expression to grap the tags of the children tags.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM