使用 xml 元素树解析 Errno22
Parsing Errno22 with xml Element Tree
我正在尝试开发一种简单的网络抓取工具,并且一直对所用 XML 文件的解析代码有问题。
每当我 运行 它给我 Errno22,即使路径是有效的。有人可以帮忙吗?
try:
xmlTree = ET.parse('C:\TestWork\RWPlus\test.xml')
root = xmlTree.getroot()
returnValue = root[tariffPOS][childPOS].text
return returnValue
except Exception as error:
errorMessage = "A " + str(
error) + " error occurred when trying to read the XML file."
ErrorReport(errorMessage)
您应该转义 Python 字符串中的反斜杠
ET.parse('C:\TestWork\RWPlus\test.xml')
或者您可以使用原始字符串(注意 r
)
ET.parse(r'C:\TestWork\RWPlus\test.xml')
我正在尝试开发一种简单的网络抓取工具,并且一直对所用 XML 文件的解析代码有问题。
每当我 运行 它给我 Errno22,即使路径是有效的。有人可以帮忙吗?
try:
xmlTree = ET.parse('C:\TestWork\RWPlus\test.xml')
root = xmlTree.getroot()
returnValue = root[tariffPOS][childPOS].text
return returnValue
except Exception as error:
errorMessage = "A " + str(
error) + " error occurred when trying to read the XML file."
ErrorReport(errorMessage)
您应该转义 Python 字符串中的反斜杠
ET.parse('C:\TestWork\RWPlus\test.xml')
或者您可以使用原始字符串(注意 r
)
ET.parse(r'C:\TestWork\RWPlus\test.xml')