in lxml.html how do i grab the text, children and content of children of a node?
开发者_C百科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?
The Element
's text_content method returns the text of the element, including the text content of its children with no markup.
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.
精彩评论