天气预报查询系统爬虫
时间: 2023-12-18 14:04:22 浏览: 103
以下是一个基于Python的天气预报查询系统爬虫的例子:
```python
import requests
from bs4 import BeautifulSoup
# 输入城市名称
city = input("请输入城市名称:")
# 构造URL
url = "http://wthrcdn.etouch.cn/weather_mini?city=" + city
# 发送请求
response = requests.get(url)
# 解析数据
data = response.json()
weather_data = data.get("data")
# 打印天气信息
print("城市:", weather_data.get("city"))
print("温度:", weather_data.get("wendu"), "℃")
print("感冒指数:", weather_data.get("ganmao"))
print("风力风向:", weather_data.get("fengxiang"), weather_data.get("fengli"))
print("空气质量:", weather_data.get("aqi"))
# 打印未来15天天气信息
forecast = weather_data.get("forecast")
for i in range(len(forecast)):
print("日期:", forecast[i].get("date"))
print("最高温度:", forecast[i].get("high"))
print("最低温度:", forecast[i].get("low"))
print("天气状况:", forecast[i].get("type"))
print("风力风向:", forecast[i].get("fengxiang"), forecast[i].get("fengli"))
print("===================================")
# 数据绘图处理和保存
# 这里可以使用Matplotlib等库进行数据绘图处理,并使用Pandas等库进行数据保存
```
阅读全文