I am using Python and need to find and retrieve all character data between tags:
I need this stuff
I then want to output
I quite like parsing into element tree and then using element.text
and element.tail
.
It also has xpath like searching
>>> from xml.etree.ElementTree import ElementTree
>>> tree = ElementTree()
>>> tree.parse("index.xhtml")
>>> p = tree.find("body/p") # Finds first occurrence of tag p in body
>>> p
>>> p.text
"Some text in the Paragraph"
>>> links = p.getiterator("a") # Returns list of all links
>>> links
[, ]
>>> for i in links: # Iterates through all found links
... i.attrib["target"] = "blank"
>>> tree.write("output.xhtml")