前言
Echarts是一个开源的数据可视化JS库,pyecharts是一款将python与echarts结合的强大的数据可视化工具
开发环境
- python 3.8
- pycharm 2022.3.2
完整源码看这里这里👈👈👈
先来获取我们想要的天气数据
请求数据
因为是静态网站,所以数据还是很好找到的,F12打开开发者工具,刷新下网站就行了
url = 'http://www.weather.com.cn/weather1d/101250101.shtml'
headers = {
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.0.0 Safari/537.36'
}
response = requests.get(url=url, headers=headers)
解析数据
用正则可以直接匹配我我们想要的数据
html_data = re.findall('var hour3data=(.*)', response.text)[0]
json_data = json.loads(html_data)
print(json_data)
提取数据
for index in json_data['7d']:
print(index)
for i in index:
dit = {
'时间': i.split(',')[0],
'天气': i.split(',')[2],
'温度': i.split(',')[3],
'风向': i.split(',')[4],
'风级': i.split(',')[5],
}
print(dit)