首页 > 代码库 > python 读取yahoo 天气api 获取北京天气情况
python 读取yahoo 天气api 获取北京天气情况
代码如下:
#!/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")
python 读取yahoo 天气api 获取北京天气情况
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。