【发布时间】:2014-03-31 14:45:34
【问题描述】:
我有一个有效的 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
是否可以使用 ns:element 语法找到带有 find 的名称空间元素?
【问题讨论】:
标签: python xml elementtree