By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,767 Members | 1,987 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,767 IT Pros & Developers. It's quick & easy.

Universal Feed Parser - How do I keep attributes?

P: n/a
I'm trying to use FeedParser to parse out Yahoo's Weather Data. I need
to capture some attribute values, but it looks like FeedParser strips
them out. Is there any way to keep them?

XML Snippet:
....
<yweather:location city="Sunnyvale" region="CA" country="US" />
....

When I try to get the value, it's empty:
>>d = feedparser.parse('http://weather.yahooapis.com/forecastrss?p=94089')
d.feed.yweather_location
u''

Jan 10 '07 #1
Share this Question
Share on Google+
3 Replies


P: n/a
At Wednesday 10/1/2007 14:38, sn*******@gmail.com wrote:
>d = feedparser.parse('http://weather.yahooapis.com/forecastrss?p=94089')
d.feed.yweather_location
u''
You have to feed it the *contents* of the page, not its URL.
--
Gabriel Genellina
Softlab SRL


__________________________________________________
Preguntá. Respondé. Descubrí.
Todo lo que querías saber, y lo que ni imaginabas,
está en Yahoo! Respuestas (Beta).
¡Probalo ya!
http://www.yahoo.com.ar/respuestas

Jan 11 '07 #2

P: n/a
Gabriel Genellina <ga******@yahoo.com.arwrote:
At Wednesday 10/1/2007 14:38, sn*******@gmail.com wrote:
>>d =
feedparser.parse('http://weather.yahooapis.com/forecastrss?p=
94089')
>>d.feed.yweather_location
u''

You have to feed it the *contents* of the page, not its URL.

The online documentation disagrees with you:

http://feedparser.org/docs/introduction.html
max

Jan 11 '07 #3

P: n/a
At Thursday 11/1/2007 12:01, Max Erickson wrote:
>Gabriel Genellina <ga******@yahoo.com.arwrote:
At Wednesday 10/1/2007 14:38, sn*******@gmail.com wrote:
>d =
feedparser.parse('http://weather.yahooapis.com/forecastrss?p=
94089')
>d.feed.yweather_location
u''
You have to feed it the *contents* of the page, not its URL.

The online documentation disagrees with you:

http://feedparser.org/docs/introduction.html
You're right, sorry.
Anyway this parser can't cope with attributes in custom elements -
they're just ignored. Only the contents are retained. For the
yweather namespace it's useless then, since attributes are used to
store all the information:

<yweather:location city="Sunnyvale" region="CA" country="US" />
<yweather:units temperature="F" distance="mi" pressure="in" speed="mph" />
<yweather:wind chill="47" direction="350" speed="8" />
<yweather:atmosphere humidity="38" visibility="1609"
pressure="30.02" rising="2" />

You may try a different library. A generic XML approach like
ElementTree http://effbot.org/zone/element-index.htm should be fine.
--
Gabriel Genellina
Softlab SRL


__________________________________________________
Preguntá. Respondé. Descubrí.
Todo lo que querías saber, y lo que ni imaginabas,
está en Yahoo! Respuestas (Beta).
¡Probalo ya!
http://www.yahoo.com.ar/respuestas

Jan 12 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.