from xml.etree import ElementTree
from html5lib import HTMLParser
parser = HTMLParser(namespaceHTMLElements=False)
tree = parser.parse('''
foo
<h1>Moonlight</h1>
bar''')
for e in tree.findall('.//h1'):
e.text = 'Sunshine'
print(ElementTree.tostring(etree))
1条答案
按热度按时间zfciruhq1#