代码如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
#!/usr/bin/env python # coding=utf-8 import urllib2 import xml.dom.minidom try: url="http://weather.yahooapis.com/forecastrss?u=c&w=2151330" request = urllib2.Request(url) response = urllib2.urlopen(request) print "Geting data from yahooapis...." data = response.read() #print data dom = xml.dom.minidom.parseString(data) root = dom.documentElement location = root.getElementsByTagName('yweather:location') city = location[0].getAttribute("city") weather_conditions=root.getElementsByTagName('yweather:condition') weather = weather_conditions[0].getAttribute('text') temp = weather_conditions[0].getAttribute('temp') print "City:",city print "weather:",weather print "temp:",temp except Exception: print("there is something wrong") |
Latest posts by Zhiming Zhang (see all)
- aws eks node 自动化扩展工具 Karpenter - 8月 10, 2022
- ReplicationController and ReplicaSet in Kubernetes - 12月 20, 2021
- public key fingerprint - 5月 27, 2021