另一个抓天气小脚本

"""用于查看天气的小脚本"""
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('&nbsp;','')
  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('&nbsp;','')
  tt=unicode(tt,'utf8','ignore')
  print tt,
n=raw_input('\n\n finished')

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值