zipfile 读取压缩包里的xml内容为gbk时报错
我在使用zipfile读取压缩包里的xml内容时因为内容时gbk的,报错:
ValueError: multi-byte encodings are not supported
以下为xml的内容,xml最后一行会多出一个空行:
<?xml version="1.0" encoding="GBK"?>
<data-bus>
<TONGZHISXJ>
<FUJIANLB><!-- 空记录 --></FUJIANLB>
</TONGZHISXJ>
</data-bus>
以下是我读取zip里xml内容的代码:
"""zip内容有:
1.jpg
2.png
3.xml等
"""
zipfilename="E:\python\1.zip"
with zipfile.ZipFile(zipfilename, 'r') as zfile:
nl = zfile.namelist()
for id,xl in enumerate(nl):
if ".xml" in xl:
aa=zfile.open(xl,'r')
xml_srt=aa.read()
doc=parseString(xml_srt)#这里出现ValueError: multi-byte encodings are not supported
python3.7,win10
百度和谷歌都没有找到处理方法,有大佬知道怎么解决么?
推荐文章: