【问题标题】:Retrieving the correct .json for wunderground为 wunderground 检索正确的 .json
【发布时间】:2017-02-06 02:51:45
【问题描述】:

到目前为止,我已经生成了以下代码:

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

为了检索天气数据,我很难理解自己做错了什么。

【问题讨论】:

    标签: python json python-2.7 python-requests


    【解决方案1】:

    看起来您的查询返回了一个可能匹配项的列表,每个匹配项都有一个包含链接的 l 键。使用该链接可以带回该位置的完整数据。例如,英国伦敦的完整数据位于http://api.wunderground.com/api/a8c3e5ce8970ae66/conditions/q/zmw:00000.1.03772.json

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-01-01
      • 1970-01-01
      • 2018-04-02
      • 1970-01-01
      • 1970-01-01
      • 2012-09-30
      • 1970-01-01
      • 2017-12-08
      相关资源
      最近更新 更多