import xml.etree.ElementTree as xml
s = '<p>blah <b>bleh</b> blih</p>\n'
t = xml.fromstring(s)
"""""".join([t.text] + [xml.tostring(e) for e in t.getchildren()])
How do I get the full XML or HTML content of an element using ElementTree?