Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Universal Feed Parser - How do I keep attributes?

Reply
Thread Tools

Universal Feed Parser - How do I keep attributes?

 
 
snewman18@gmail.com
Guest
Posts: n/a
 
      01-10-2007
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''

 
Reply With Quote
 
 
 
 
Gabriel Genellina
Guest
Posts: n/a
 
      01-11-2007
At Wednesday 10/1/2007 14:38, 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

 
Reply With Quote
 
 
 
 
Max Erickson
Guest
Posts: n/a
 
      01-11-2007
Gabriel Genellina <gagsl-> wrote:

> At Wednesday 10/1/2007 14:38, 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

 
Reply With Quote
 
Gabriel Genellina
Guest
Posts: n/a
 
      01-12-2007
At Thursday 11/1/2007 12:01, Max Erickson wrote:

>Gabriel Genellina <gagsl-> wrote:
>
> > At Wednesday 10/1/2007 14:38, 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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
Universal Feed Parser issue i3dmaster Python 8 04-12-2007 03:50 AM
Sigma Announces SD-30--30 Megapixel,Universal Lens Mount, Digital SLRSigma Announces SD-30--30 Megapixel,Universal Lens Mount, Digital SLR sigmaphotojapan@yahoo.com Digital Photography 6 04-01-2005 05:26 PM
Sigma Announces SD-30--30 Megapixel,Universal Lens Mount, Digital SLRSigma Announces SD-30--30 Megapixel,Universal Lens Mount, Digital SLR sigmaphotojapan@yahoo.com Digital Photography 5 04-01-2005 02:08 PM
Freelance job: Store Universal Feed Parser data in MySQL Jacob Friis Larsen Python 0 08-05-2004 12:03 PM



Advertisments