Universal Feed Parser - How do I keep attributes?

Discussion in 'Python' started by snewman18@gmail.com, Jan 10, 2007.

  1. Guest

    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, 2007
    #1
    1. Advertising

  2. 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
     
    Gabriel Genellina, Jan 11, 2007
    #2
    1. Advertising

  3. Max Erickson Guest

    Gabriel Genellina <> 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
     
    Max Erickson, Jan 11, 2007
    #3
  4. At Thursday 11/1/2007 12:01, Max Erickson wrote:

    >Gabriel Genellina <> 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
     
    Gabriel Genellina, Jan 12, 2007
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    2
    Views:
    388
  2. Sebastian Eichinger

    a href title - how to hide universal attributes?

    Sebastian Eichinger, May 29, 2006, in forum: HTML
    Replies:
    16
    Views:
    1,709
    Sebastian Eichinger
    May 31, 2006
  3. Jacob Friis Larsen
    Replies:
    0
    Views:
    348
    Jacob Friis Larsen
    Aug 5, 2004
  4. i3dmaster

    Universal Feed Parser issue

    i3dmaster, Apr 10, 2007, in forum: Python
    Replies:
    8
    Views:
    430
    Gabriel Genellina
    Apr 12, 2007
  5. Virgil Stokes
    Replies:
    0
    Views:
    490
    Virgil Stokes
    Feb 7, 2011
Loading...

Share This Page