lxml.etree, element.text doesn’t return the entire text from an element

Use element.xpath("string()") or lxml.etree.tostring(element, method="text") - see the documentation.

https://lxml.de/tutorial.html#elements-contain-text

Another thing that seems to be working well to get the text out of an element is

"".join(element.itertext())

https://stackoverflow.com/questions/4770191/lxml-etree-element-text-doesnt-return-the-entire-text-from-an-element

Leave a Comment