首页 > 其他 > 详细

杭州七日天气预报数据分析

时间:2020-05-10 21:12:37      阅读:51      评论:0      收藏:0      [点我收藏+]

技术分享图片

import requests as r
from bs4 import BeautifulSoup
import matplotlib.pyplot as p
def gethtmltext(url):
try:
a=r.get(url,timeout=30)
a.raise_for_status()
r.encoding=a.apparent_encoding
return a.text
except:
return ‘‘
url=‘http://www.weather.com.cn/weather/101210101.shtml‘
html=gethtmltext(url)
soup=BeautifulSoup(html,‘html.parser‘)
t_high=[]
t_low=[‘17‘]
for tr in soup.find_all(‘p‘,{‘class‘:‘tem‘}):
x=tr.get_text()
t_high.append(eval(x[1:3]))
t_low.append(x[5:7])
p.xlabel(‘时间(5月x日)‘,fontproperties=‘SimHei‘)
p.ylabel(‘温度(单位:℃)‘,fontproperties=‘SimHei‘)
p.title(‘杭州未来一周温度预测‘,fontproperties=‘SimHei‘)
x=range(10,17)
m=[24,28,28,29,25,30,29]
n=[17,17,17,18,19,21,20]
p.plot(x,m,marker=‘^‘)
p.plot(x,n,marker=‘^‘)
p.show()

杭州七日天气预报数据分析

原文:https://www.cnblogs.com/xiongly/p/12864741.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!