众所周知中国天气网提供的有个公共天气预报API接口,但是不知道咋的一直停在3月4号不更新了。最近做个天
气方面的APP需要用到一些天气数据,360的接口公司不让用。只好自己写一个python脚本放数据中心。
先发三个尚还能用的接口,据说万年历有未来7天预报的api。
http://weather.com.cn/data/zs/101280601.html 各种各样的指数
http://weather.com.cn/data/cityinfo/101280601.html 简洁天气信息
http://weather.com.cn/data/sk/101280601.html 实况天气
获取未来15天温度
#coding=utf-8
import urllib,re,MySQLdb,ConfigParser,datetime,time
y=time.strftime("%Y")
m=time.strftime("%m")
d=time.strftime("%d")
now=y+'-'+m+'-'+d
todaylow=99;
todayhigh=99;
print now
def getHtml(url):
page = urllib.urlopen(url)
html = page.read()
return html
def getRel(html,reg):
mre = re.compile(reg)
relList = re.findall(mre,html)
return relList
html = getHtml("http://weather.com.cn/weather/101280601.shtml")
reg1 = r'<