views:

126

answers:

1

Hello, 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!

+1  A: 

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']
systempuntoout
Yes! In my xml file it has namespace geo:lat and geo:long diclaration! But How to parse then? for example :<geo:lat>60.187953</geo:lat> <geo:long>24.803031</geo:long> , this is one item in my xml file! Do you mean any other speciafication as well?
rahman.bd
Yes mine xml file has the same declaration as you told! But I couldn't get the parsed lat and long from this file! Could you please give me hints of code sample that I can get it?
rahman.bd
@rahman.db give it a try, look at the snippet.
systempuntoout
I have tried but they showed error that:AttributeError: object has no attribute 'geo_lat'so perhaps geo_lat attribute not found! What else then?
rahman.bd
@systempuntoout: Mine parse argument is just web URL , not just .xml file!so what I can do with this? do you have idea?
rahman.bd
Could you post the URL to the feed you are trying to parse?
systempuntoout
Well as this URL is related to location so I can't give the exact! But the format is :http://geofeed.elisalabs.fi/web/rss/Lrge432sG173Dc44561CDDHope you understand!
rahman.bd
It needs authentication!Please, try to pastebin your Xml http://pastebin.ca/.
systempuntoout
I have pasted there! But what now?
rahman.bd
You have to save the link to pastebin :)..Anyway, i've updated the snippet.Give it a try.
systempuntoout
@systempuntoout: thanks, it works!..Yes I need to save :D..
rahman.bd
you are welcome :D!
systempuntoout