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()
相关文章:
- IP得到天气预报(1)———数据分析存储 2021-12-16
- 获取天气预报及天气预警接口数据 2021-11-06
- 免费天气预报接口,提供七天预报 2018-02-03
- 数据分析沙龙杭州站,邀您报名! 2021-05-10
- Android解析聚合数据之天气预报 2022-12-23
- AJAX(七)jsonp实战--天气预报 2022-01-13
- 数值天气预报 2021-12-04