•
•
•
•
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
![]() |
•
•
Join Date: Dec 2007
Posts: 1
Reputation:
Rep Power: 0
Solved Threads: 0
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?
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?
python Syntax (Toggle Plain Text)
import xml.etree.ElementTree as et import urllib2 # get the weather off the web weather_online = urllib2.urlopen("http://weather.yahooapis.com/forecastrss?p=94089&u=c") # except, that's an object, make it actual xml weather_web = weather_online.read() weather_cache = open(".\weather_cache.xml", "wb") weather_cache.write(weather_web) # Parse it weather_xml = et.XML(weather_web) # print the actual XML we are working off out # print weather_web # and read it into variables vars = {} for item in weather_xml: print item.text vars[item.tag] = item.text
![]() |
•
•
•
•
•
•
•
•
DaniWeb Python Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
- Previous Thread: Help with Homework
- Next Thread: Dreamweaver + Python + CGI Script


Linear Mode