2024-10-01 07:42:17 发布
网友
我有以下xml:
<Earth> <country name="Česká republika" population="8900000"> <capital>Praha1</capital> </country> </Earth>
但当我试图解析它时,却出现了错误:
我的代码:
tree=etree.parse(input) # input -> file.xml
正如arhimmel指出的,这个问题很可能是编码问题。etree.parse允许传递类似文件的对象和路径,因此您可以尝试在代码顶部添加import codecs,然后将input替换为codecs.open("file.xml", encoding="UTF-8")。在
import codecs
input
codecs.open("file.xml", encoding="UTF-8")
正如arhimmel指出的,这个问题很可能是编码问题。etree.parse允许传递类似文件的对象和路径,因此您可以尝试在代码顶部添加
import codecs
,然后将input
替换为codecs.open("file.xml", encoding="UTF-8")
。在相关问题 更多 >
编程相关推荐