开发者

Parsing <geo:lat>, <geo:long> tags value using feedparser in python!

开发者 https://www.devze.com 2022-12-26 17:17 出处:网络
I am using feedparser for parsing from XML file.But I couldn\'t parse <开发者_如何学编程geo:lat>, <geo:long> tags using feedparser from that file! Do you people have any idea how I can par

I am using feedparser for parsing from XML file.But I couldn't parse <开发者_如何学编程geo:lat>, <geo:long> tags using feedparser from that file! Do you people have any idea how I can parse those tags using feedparser in python?

Thanks in advance!


Feedparser should parse Basic Geo namespace with extension name geo without problem.
Check that your XML has http://www.w3.org/2003/01/geo/wgs84_pos# namespace declaration like:

xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#"

This snippet should work:

 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/">

working example:

import feedparser

for item in d['items']`  
    print item['geo_lat']
    print item['geo_long']
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号