Python格式化xml文件

在使用Python构建XML文件的时候,默认是没有缩减的。

发现BeautifulSoup自带自动缩减

方法如下:

1
2
3
4
5
from bs4 import BeautifulSoup
bs = BeautifulSoup(open(tmp_file), 'xml')

with open(filename, 'w', encoding='utf-8') as f:
f.write(bs.prettify())

评论

You need to set client_id and slot_id to show this AD unit. Please set it in _config.yml.
Your browser is out-of-date!

Update your browser to view this website correctly.&npsb;Update my browser now

×