That is, all text and subtags, without the tag of an element itself?
Having
<p>blah <b>bleh</b> blih</p>
I want
blah <b>bleh</b> blih
element.text returns "blah " and etree.tostring(element) returns:
This is the solution I ended up using:
def element_to_string(element): s = element.text or "" for sub_element in element: s += etree.tostring(sub_element) s += element.tail return s