其他分享
首页 > 其他分享> > 杭州七日天气预报数据分析

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

作者:互联网

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()

标签:数据分析,17,SimHei,url,七日,fontproperties,html,import,天气预报
来源: https://www.cnblogs.com/xiongly/p/12864741.html