#!/usr/bin/env python# encoding: utf-8import reimport requests#定义访问地址列表,因为地址没有通配匹配所以没办法写正则url = ['http://chengdu.tianqi.com/','http://chengdu.tianqi.com/chongzhou/','http://chengdu.tianqi.com/dayi/','http://chengdu.tianqi.com/dujiangyan/','http://chengdu.tianqi.com/jintang/','http://chengdu.tianqi.com/longquanyi/','http://chengdu.tianqi.com/pixian/','http://chengdu.tianqi.com/pujiang1/','http://chengdu.tianqi.com/pengzhou/','http://chengdu.tianqi.com/qionglai/','http://chengdu.tianqi.com/shuangliu/','http://chengdu.tianqi.com/wenjiang/','http://chengdu.tianqi.com/xindu/','http://chengdu.tianqi.com/xinjin/',]#循环访问地址for html in url: html=requests.get(html) detail = html.content.decode('gbk').encode('utf-8') detail1 = re.findall('(.*?)',detail,re.S) temper = re.findall(' (.*?)',str(detail1),re.S) content = temper[0].replace('°','°') cityall = re.findall('(.*?)',detail,re.S) city = [] for i in cityall: city = re.findall('(.*?)
',i,re.S) for i in city: print i + ':' + content a = i + ':' + content + '\n' with open('temperature.txt','a+') as obj: obj.write(a)with open('temperature.txt','a+') as obj: obj.write('==================' + '\n') 说明:成都当前温度
50- 25- 0- -25- -50-9.6° 相对湿度:99%