输入地名获得当地天气预报,地名当地天气预报,weather.py#!
输入地名获得当地天气预报,地名当地天气预报,weather.py#!
weather.py
#!/usr/bin/env python#coding=utf-8import urllib ,sysimport reprovice=raw_input('输入省名(请使用拼音):');major=raw_input("输入市名(请使用拼音):")url="http://qq.ip138.com/weather/"+provice+'/'+major+'.htm'print url#url="http://www.baidu.com"wetherhtml=urllib.urlopen(url)result=wetherhtml.read().decode('GB2312')#.encode('utf-8')#result=result.replace("gb2312","utf-8")f=file('weather.txt','w')f.write(result.encode('GB2312'))f.close()pattern='Title.+<b>(.+)</b>'Title=re.search(pattern,result).group(1)pattern='>(\d*-\d*-\d*.+?)<'date=re.findall(pattern,result)pattern='alt="(.+?)"'weather=re.findall(pattern,result)pattern='<td>([-]?\d{1,2}.+)</td>'temperature=re.findall(pattern,result)print "%35.30s"%Title,""length=len(date)for i in range(length): print '%30.20s'%date[i],'\t%s'%weather[i],'\t%s'%temperature[i]
相关内容
- python根据月份和日得到星座,python星座,#计算星座def
- python获取图片的颜色信息,,image = Imag
- python中使用sorted函数对列表进行排序,pythonsorted,#创建
- 使用python获取糗百图片,,from sgmllib
- python使用smtplib模块通过gmail发送邮件,pythonsmtplib,impo
- python编写的一个简单那的WSGI PDF server,pythonwsgi,# basic
- xapian通过python实现的一个简单的范围查询的例子,xap
- 利用python下载百度空间文章,,#! /usr/bin/
- Python 自动连接ssh,Python连接ssh,[Python]代码#!
- Python中的工厂方法 funtional的思维来做 非oop的实现,f
评论关闭