使用XPath我有一個XML文件,如下如何LXML Python模塊
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<url>
<loc>https://ezinearticles.com/</loc>
<changefreq>hourly</changefreq>
<priority>1.0</priority>
</url>
<url>
<loc>https://ezinearticles.com/submit/</loc>
<changefreq>weekly</changefreq>
<priority>0.3</priority>
</url>
...................
我想用xpathin LXML模塊從所有的代碼中獲得URL。我實現它作爲下面的代碼,但它沒有奏效。結果爲空列表
from lxml import etree
parser = etree.XMLParser(ns_clean=True)
xmlfile = "sitemap1.xml"
xmlobj = etree.parse(xmlfile, parser)
loc = xmlobj.xpath('//loc[text()]')
print(loc)
任何人都可以幫我修復我的腳本嗎?
...已批准,這個問題不是關於XHTML,而是完全相同的問題(只是使用兩個不同的命名空間)。 –