python 天气预报
来源:互联网 发布:反美颜软件app 编辑:程序博客网 时间:2024/06/14 10:47
**# -*- coding: cp936 -*-**import urllib2import re#http://qq.ip138.com/tianqi/url = "http://qq.ip138.com/10/tianqi/"class Weather(): def __init__(self): pass def getHtml(self, url): req = urllib2.Request(url) res = urllib2.urlopen(req) html = res.read() res.close() return html def getWeather(self, html): patteraddress=re.compile(r'<ul class="query-hd">(.*)</ul>') address=patteraddress.findall(html) p=re.compile(r'<li(.*?)</li>') address1=p.findall(address[0]) #print address len1=len(address1) for i in xrange(len1): riqip=re.compile(r'<div class="date">(.*?)<font color="red">(.*?)</font></div>|<div class="date">(.*?)</div>') riqi=riqip.findall(address1[i]) print '----------------------------------' if i==0: print (riqi[0][0]+riqi[0][1]).decode('utf8') else: print riqi[0][-1].decode('utf8') tianqip=re.compile(r'alt="(.*?)"') tianqi=tianqip.findall(address1[i]) for j in tianqi: print j.decode('utf8') wendup=re.compile(r'<div class="temperature">(.*?)</div>') wendu=wendup.findall(address1[i]) for i in wendu: print i.decode('utf8') print '----------------------------------'if __name__ == "__main__": weather = Weather() weather.getWeather(weather.getHtml(url)) input()
“`
阅读全文
0 0
- python天气预报
- python 天气预报
- Python 天气预报
- python 的查询天气预报
- python 实现天气预报功能
- Python读取天气预报
- Python查询天气预报
- python获取天气预报
- 初学Python---------------天气预报
- Python查询天气预报
- Python接入天气预报api
- python 天气预报获取
- 【python 天气预报】python制作属于自己的天气预报
- python for android : 天气预报 API
- python 获取省份的天气预报
- 天气预报
- 天气预报
- 天气预报
- 《C语言程序设计教程》(主编黄迪明、余勤)第三章课后习题答案
- UITableViewCell根据内容显示不同的高度问题
- css水平垂直居中
- 剑指offer面试题[36]-数组中的逆序对
- 如何让Oracle数据库保持优良性能的方法
- python 天气预报
- bzoj4530[Bjoi2014]大融合 线段树合并+dfs序+并查集
- poi导入excl
- ng-container的使用
- VC++实现程序只运行一个实例 最简单办法
- 元素内容根据div大小自动换行
- 写高质量OC代码52建议总结:38.为常用的块创建typedef
- 0710学习总结(友元函数,string函数,引用)
- python新手入门(五)