That is, all text and subtags, without the tag of an element itself?
Having
blah bleh blih
I
Most of the answers here are based on the XML parser ElementTree
, even PEZ's regex-based answer still partially relies on ElementTree.
All those are good and suitable for most use cases but, just for the sake of completeness, it is worth noting that, ElementTree.tostring(...)
will give you an equivalent snippet, but not always identical to the original payload. If, for some very rare reason, that you want to extract the content as-is, you have to use a pure regex-based solution. This example is how I use regex-based solution.