东南地区连续突破历史,江浙沪还获得了包邮以外的另一项福利——桑拿。 在这样的日子里应该每天注意天气主义的炎热,避免热疾病,因为python包含比较多的网络APP类,网络APP的操作变得容易。 另外,还有可以和c竞争的接口。 这次结合这两个优势制作了中国气象网的爬行动物,爬上来将数据保存在txt中,然后在界面框中显示。
源代码如下所示。
#--coding:CP936----#识别中文代码
加载import urllib2#网络库
import re#搜索到的函数库
reg='a title=.*? () )? (/a.)? span(.*? /span.*? B(.*? /b'#正则表达式
URL=' http://www.weather.com.cn/Shanghai/index.shtml ' #气象网上海的预报页面
打开page=urllib2.urlopen(URL ).read页面害怕数据
weatherlist=re.compile(reg ).findall ) page )根据正则表达式找到所需的数据
a=' c ://users/xww/desktop/Shanghai Tianqi.txt ' #存储位置-您的桌面位置
uipath=unicode(a,' utf8 ' )气象数据的编码格式转换
f=open(a,' w ' ) ) )。
f=open(a,' r ' ) ) )。
for weather in weatherList:
city=str(weather[0] ).decode (