Unicode strings with encoding declaration are not supported. Please use bytes input or XML fragments
这里的xml_data是str类型的,报错的是:Unicode strings with encoding declaration are not supported. Please use bytes input or XML fragments。所以,我们首先需要把数据转换为字节类型,那么就需要进行编码(encode)xml_data = open(ii).read()root = etree
·
xml_data = open(ii).read()
root = etree.fromstring(xml_data, parser=parser)
这里的xml_data是str类型的,报错的是:
Unicode strings with encoding declaration are not supported. Please use bytes input or XML fragments。
所以,我们首先需要把数据转换为字节类型,那么就需要进行编码(encode)
修改之后的代码:
xml_data = open(ii).read()
xml_data = xml_data.encode('ascii')
root = etree.fromstring(xml_data, parser=parser) # element tree
更多推荐
所有评论(0)