到目前为止,我已经生成了以下代码:
import requests
def weatherSearch():
Search = raw_input('Enter your location: ')
r = requests.get("http://api.wunderground.com/api/a8c3e5ce8970ae66/conditions/q/{}.json".format(Search))
weatherData = r.json()
print weatherData
weatherSearch()例如,如果Search设置为London,它将生成:
http://api.wunderground.com/api/a8c3e5ce8970ae66/conditions/q/London.json
但是,这个.json没有包含我要查找的温度:"temp_c":
而在下面的链接中,可以找到"temp_c"::
http://api.wunderground.com/api/a8c3e5ce8970ae66/conditions/q/CA/San_Francisco.json
为了检索天气数据,我正在努力理解我做错了什么。
发布于 2016-09-28 16:49:31
看起来您的查询返回了一个可能的匹配项列表,每个匹配项都有一个包含链接的l键。使用该链接可以返回该位置的完整数据。例如,英国伦敦的完整数据在http://api.wunderground.com/api/a8c3e5ce8970ae66/conditions/q/zmw:00000.1.03772.json。
https://stackoverflow.com/questions/39742176
复制相似问题