我正在使用feedparser從XML文件解析。但我無法解析使用該文件中的feedparser的<geo:lat>
,<geo:long>
標記!你們有什麼想法我可以用Python中的feedparser解析這些標籤嗎?解析<geo:lat>,<geo:long>使用python中的feedparser標籤值!
在此先感謝!
我正在使用feedparser從XML文件解析。但我無法解析使用該文件中的feedparser的<geo:lat>
,<geo:long>
標記!你們有什麼想法我可以用Python中的feedparser解析這些標籤嗎?解析<geo:lat>,<geo:long>使用python中的feedparser標籤值!
在此先感謝!
Feedparser應該解析Basic Geo命名空間,擴展名爲geo沒有問題。
檢查你的XML有http://www.w3.org/2003/01/geo/wgs84_pos#命名空間聲明,如:
xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#"
這段代碼應該工作:
import feedparser
d = feedparser.parse('http://yourfeed.xml')
print d.entries[0].['geo_lat']
print d.entries[0].['geo_long']
<rss version="2.0" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:dc="http://purl.org/dc/elements/1.1/">
工作示例:
import feedparser
for item in d['items']`
print item['geo_lat']
print item['geo_long']
是的!在我的xml文件中有名稱空間geo:lat和geo:long diclaration!但是如何解析呢?例如: 60.187953 \t 24.803031 ,這是我的xml文件中的一個項目!你的意思是否還有其他speciafication? –
2010-04-08 12:31:06
是的,我的xml文件與您所說的具有相同的聲明!但是我無法從這個文件中獲得解析的經緯度!你能否給我提示我可以得到它的代碼示例? – 2010-04-08 12:40:57
@ rahman.db試一下,看看這個片段。 – systempuntoout 2010-04-08 12:44:12