用前缀的on标记解析.xml?xml.etree.ElementTree

用前缀的on标记解析.xml?xml.etree.ElementTree,第1张

前缀的on标记解析.xml?xml.etree.ElementTree

这是将XML名称空间与 ElementTree 一起使用的示例

>>> x = '''<channel xmlns:media="http://www.w3.org/TR/html4/">  <title>Popular  Photography in the last 1 week</title>  <item>    <title>foo</title>    <media:category label="Miscellaneous">photography/misc</media:category>    <media:content url="http://foo.com/1.jpg" height="375" width="500" medium="image"/>  </item>  <item> ... </item></channel>'''>>> node = ElementTree.fromstring(x)>>> for elem in node.findall('item/{http://www.w3.org/TR/html4/}category'):        print elem.textphotography/misc


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/5664048.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-16
下一篇 2022-12-16

发表评论

登录后才能评论

评论列表(0条)

保存