473,321 Members | 1,667 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,321 software developers and data experts.

Universal Feed Parser - How do I keep attributes?

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
3 1967
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Martman | last post by:
I am new to PHP but testing the ability to read an RSS xml feed. I have successfully retrieved, read, and displayed an RSS feed from pcworld. However, when you click on one of the links it adds...
5
by: Mayhem | last post by:
I would like to integrate an RSS newsfeed into my website but can't seem to figure out how. Has anyone got any pointers for me? E.
15
by: lawrence | last post by:
I wanted to test xml_parse_into_struct() so I took the example off of www.php.net and put this code up on a site: <?php $simple = <<<END <item>
2
by: Charles Stricklin | last post by:
If I have an RSS newsfeed like this: <?xml version="1.0" encoding="utf-8"?><!-- generator="whocares" --> <rss version="0.92"> <channel> <title>Website Name</title>...
0
by: Nick Kew | last post by:
Rationale ========= Many applications today benefit from an SGML and/or XML Entity Catalogue to dereference entities referenced by a Public Identifier. For a validating SGML parser this is an...
4
by: ChillyRoll | last post by:
Hello guys, I am looking for a parser in PHP that can return all the attributes of XML entities. I know how to read the XML Entities, but I have got a problem with reading attributes. So I will...
8
by: i3dmaster | last post by:
I have a sample Atom feed like this: <?xml version='1.0' encoding='utf-8'?> <feed xmlns='http://www.w3.org/2005/Atom' xmlns:foo='http:// app.example.com/app/2007'>...
4
by: Jake G | last post by:
Hi all, I am trying to get a current weather conditions feed working. Yahoo provides a free feed @ http://weather.yahooapis.com/forecastrss?p=XXXXX where XXXXX is a valid US zip code e.g....
1
by: =?Utf-8?B?RGlmZmlkZW50?= | last post by:
Hi All, I have created an RSS feed reader. However, the feed that I am trying to read has some invalid characters which my reader does not like. I have no control on the RSS feed but I would...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.