Universal Feed Parser - How do I keep attributes?

Gabriel Genellina gagsl-py at yahoo.com.ar
Fri Jan 12 04:43:48 CET 2007


At Thursday 11/1/2007 12:01, Max Erickson wrote:

>Gabriel Genellina <gagsl-py at yahoo.com.ar> wrote:
>
> > At Wednesday 10/1/2007 14:38, snewman18 at 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 




More information about the Python-list mailing list