我有一个有效的XHTML文件。当我这么做
import xml.etree.ElementTree as ET
print ET._namespace_map它列出:
'http://www.w3.org/1999/xhtml': 'html'当我这么做时:
root.find('{http://www.w3.org/1999/xhtml}head')它认为:
<Element '{http://www.w3.org/1999/xhtml}head' at 0x104647168>但当我这么做的时候
root.find('html:head')它抱怨说:
SyntaxError: prefix 'html' not found in prefix map是否可以使用find语法ns:element找到带有名称的元素?
发布于 2014-03-31 14:52:07
您应该指定namespaces参数:
namespaces = {'html': 'http://www.w3.org/1999/xhtml'}
root.find('html:head', namespaces=namespaces)另请参阅:
https://stackoverflow.com/questions/22764681
复制相似问题