获取具有预设命名空间的节点

2024-10-04 11:23:44 发布

您现在位置:Python中文网/ 问答频道 /正文

我如何获得下面的etree节点,在这里我不必用名称空间限定每个操作?例如:

>>> c='''<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
             <sitemap><loc>http://www.vudu.com/sitemap-static.xml</loc></sitemap>
         </sitemapindex>'''
>>> node=etree.fromstring(c)
>>> node.xpath('//loc')
[]

我如何建立node这样我就可以做node.xpath(''/loc')并得到结果


Tags: org名称nodehttp节点www空间schemas