标签:weather 单位 exce show odi eth 技术 import eval
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()
标签:weather 单位 exce show odi eth 技术 import eval
原文地址:https://www.cnblogs.com/xiongly/p/12864741.html