How do I get the full XML or HTML content of an element using ElementTree?

后端 未结 7 1095
长情又很酷
长情又很酷 2020-12-30 08:18

That is, all text and subtags, without the tag of an element itself?

Having

blah bleh blih

I

相关标签:
7条回答
  • 2020-12-30 09:16

    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.

    0 讨论(0)
提交回复
热议问题