"""用于查看天气的小脚本"""
import re,urllib,urllib2
s='http://search.weather.com.cn/static/url.php'
body={}
n=raw_input('please input your local street tel number: ')
print '\n\n'
body['cityinfo']=n
ss=urllib.urlencode(body)
tem=urllib.urlopen(s,ss).read()
url=re.findall(r'URL=(.*?)">',tem)[0]
tem=urllib.urlopen(url).read()
w=open('weather.html','w')
w.write(tem)
w.close()
com=re.compile(r'<dt class="date">(.*?)<span class="f888">.*?<h3><strong>(.*?)<\/strong>\((.*?)\)<\/h3>.*?<dt>(邮政编码)<\/dt>.*?<dd><strong>.*?<a>(\d*)<\/a>',re.I|re.M|re.S)
temp=com.findall(tem)
for i in temp:
for j in i:
t=unicode(j,'utf8','ignore')
print t,
com=re.compile(r'<div class="box_contenttodayinwea" id="c_1_1">(.*?)气温趋势',re.I|re.M|re.S)
temp=com.findall(tem)
for i in temp:
print '\n'
ch=u'明天的天气'
print ch,
com=re.compile(r'>(.*?)<',re.I|re.M|re.S)
t=com.findall(i)
for j in t:
j=j.strip()
tt=j.replace('\t','')
tt=tt.replace(' ','')
tt=unicode(tt,'utf8','ignore')
print tt,
com=re.compile(r'<div class="fut_weatherbox7">(.*?)<\/div>',re.I|re.M|re.S)
temp=com.findall(tem)
for i in temp:
print '\n'
com=re.compile(r'>(.*?)<',re.I|re.M|re.S)
t=com.findall(i)
for j in t:
tt=j.replace('\t','')
tt=tt.strip()
tt=tt.replace(' ','')
tt=unicode(tt,'utf8','ignore')
print tt,
n=raw_input('\n\n finished')