python查看天气预报

今天起我将开始介绍一些网络爬虫的教程~不足之处欢迎大家指出~

这里使用的city因为年经失修忘了放哪里了,大家可以自行查找api~非常抱歉?

import requests
import city
while True:
    try:
        want = input("你想查找哪个城市?")
        citycode = city.citycode[want]
        # 访问  requests
        url = "http://t.weather.sojson.com/api/weather/city/" + citycode
        response = requests.get(url)
        # response 响应
        message = response.json()
        print(message)
        data = "城市:" + message['cityInfo']['city'] + "\n" + \
            '湿度:' + message['data']['shidu']+ "\n" + \
            "温度:" + message['data']['wendu'] + "度"
        print(data)
    except:
        print("你刚才输入的有问题")

更多精彩内容

点赞

发表回复

电子邮件地址不会被公开。必填项已用 * 标注