使用feedparser解析Python中的<geo:lat>和<geo:long>标签值!
我正在使用feedparser来解析XML文件。但是我无法用feedparser从那个文件中解析<geo:lat>和<geo:long>这两个标签!你们有没有什么主意,怎么才能用Python的feedparser解析这些标签呢?
提前谢谢大家!
相关问题:
2 个回答
0
<rss version="2.0" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:dc="http://purl.org/dc/elements/1.1/">
这是一个工作示例:
导入一个叫做 feedparser 的库
for item in d['items']`
print item['geo_lat']
print item['geo_long']
2
Feedparser应该能够顺利解析带有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']