使用Openweather JSON API,我从城市获取数据。我可以检索所有数据,我关注的数据是temp和dt_txt
我尝试过通过这样做来获取临时值,但不起作用:
import requests
def getCity():
allCityName = ["London"]
for cityName in allCityName:
url = "http://api.openweathermap.org/data/2.5/forecast?q="+ cityName +"&appid="
response = requests.get(url)
data = response.json()
print(data["main"]["temp"]
我尝试了许多组合,但似乎总是得到一个错误或没有结果。 任何帮助都将不胜感激
也许你没有意识到这一点,但每个城市都会返回超过1条temp和dt_文本。所以,除非你知道你想要第一个,最后一个,或者中间的某个地方,你不能把它拔出来。或者,如果你想要它们,你必须把它们收集在一个列表中,例如
相关问题 更多 >
编程相关推荐