User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Python section within the Software Development category of DaniWeb, a massive community of 423,863 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,968 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Python advertiser: Programming Forums
Views: 550 | Replies: 0
Reply
Join Date: Dec 2007
Posts: 1
Reputation: elomis is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
elomis elomis is offline Offline
Newbie Poster

Help XML parsing the weather

  #1  
Dec 16th, 2007
Hey guys, new poster so if I am in the wrong spot please just let me know.
The below code should read the weather off Yahoo, and create a dictionary containing a bunch of variables and their values from the weather (temp = 9 or whatever), it doesn't. How is it possible to read in some XML, parse it, and spit out some variables that make sense?

  1. import xml.etree.ElementTree as et
  2. import urllib2
  3.  
  4. # get the weather off the web
  5.  
  6. weather_online = urllib2.urlopen("http://weather.yahooapis.com/forecastrss?p=94089&u=c")
  7.  
  8. # except, that's an object, make it actual xml
  9.  
  10. weather_web = weather_online.read()
  11.  
  12.  
  13. weather_cache = open(".\weather_cache.xml", "wb")
  14. weather_cache.write(weather_web)
  15.  
  16. # Parse it
  17.  
  18. weather_xml = et.XML(weather_web)
  19.  
  20. # print the actual XML we are working off out
  21.  
  22. # print weather_web
  23.  
  24. # and read it into variables
  25. vars = {}
  26. for item in weather_xml:
  27. print item.text
  28. vars[item.tag] = item.text
  29.  
AddThis Social Bookmark Button
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb Python Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Other Threads in the Python Forum

All times are GMT -4. The time now is 4:04 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC