Universal Feed Parser - How do I keep attributes?

S

snewman18

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:
u''
 
G

Gabriel Genellina

At said:

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
 
G

Gabriel Genellina

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Staff online

Members online

Forum statistics

Threads
473,767
Messages
2,569,570
Members
45,045
Latest member
DRCM

Latest Threads

Top