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

后端 未结 7 1133
长情又很酷
长情又很酷 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:00

    I doubt ElementTree is the thing to use for this. But assuming you have strong reasons for using it maybe you could try stripping the root tag from the fragment:

     re.sub(r'(^<%s\b.*?>|$)' % (element.tag, element.tag), '', ElementTree.tostring(element))
    

提交回复
热议问题