Tan*_*ash 12 python xml beautifulsoup
我正在编写一个用于编辑XML文件的脚本BeautifulStoneSoup
,但该库会将所有标记转换为小写.是否可以选择保存案例?
import BeautifulSoup
xml = "<TestTag>a string</TestTag>"
soup = BeautifulSoup.BeautifulStoneSoup(xml, markupMassage=False)
print soup.prettify() # or soup.renderContents()
#prints
>>> <testtag>a string</testtag>
#instead of the expected
>>> <TestTag>a string</TestTag>
Run Code Online (Sandbox Code Playgroud)
mzj*_*zjn 15
您可以使用Beautiful Soup 4,如下所示(需要lxml XML库):
In [10]: from bs4 import BeautifulSoup
In [11]: xml = "<TestTag>a string</TestTag>"
In [12]: soup = BeautifulSoup(xml, "xml")
In [13]: print soup
<?xml version="1.0" encoding="utf-8"?>
<TestTag>a string</TestTag>
In [14]:
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
3172 次 |
最近记录: |