【发布时间】:2017-09-09 23:03:03
【问题描述】:
我使用 bs4 更改了 XML 中某些元素的一些数字字符串,但是当我将 XML 保存为文件时,我不希望 html 或 body 标记出现在 XML 中。
<annotation>
... more stuff here
</annotation>
变成
<html>
<body>
<annotation>
... more stuff here
</annotation>
</body>
</html>
加载后通过
soup = BeautifulSoup(file_obj.read(), 'lxml')
我想在保存之前美化我的 XML,但现在转换汤 -> 字符串然后扔掉我不想要的元素更容易。
链接到我正在使用的一个完整 XML 文件:https://gist.github.com/jtara1/4e583160441976e198aba2c7651aaf70
【问题讨论】:
标签: python xml beautifulsoup bs4