天气预报(Python3.4 re和urllib2的使用)
来源:互联网 发布:js window.android 编辑:程序博客网 时间:2024/04/28 07:52
import urllib.request as requestimport redef getHtml(url): html= request.urlopen(url).read().decode() return htmldef getweather(html): try: weatherlist1=re.compile(r'<a title="(.+?)天气预报"').findall(html) weatherlist2=re.compile(r'target="_blank"><img alt="(.+?)"').findall(html) weatherlist3=re.compile(r'target="_blank"><span>(.+?)</span></a>/<a ').findall(html) weatherlist4=re.compile(r'target="_blank"><b>(.+?)</b').findall(html) time=re.compile(r'span="4">(.+?)的预报<').findall(html) print(time[0]) for i in (range(0,len(weatherlist1))): print(weatherlist1[i],' ',weatherlist2[i],' ',weatherlist3[i],'/',weatherlist4[i]) except: print('获取失败,请重试!')url='http://henan.weather.com.cn/index.shtml'a=getHtml(url)a=getweather(a)
0 0
- 天气预报(Python3.4 re和urllib2的使用)
- Python3的re.match()、re.search()和re.findall()
- Python3的re.match()、re.search()和re.findall()
- Python3.4找不到urllib2
- python3.x中urllib和urllib2包的更新
- urllib和urllib2的区别和使用
- urllib2和requests的基本使用
- Python3 安装bulitwith 和urllib2包
- Python3 下找不到urllib2的问题
- python3的urllib2报错问题解决方法
- python3的urllib2报错问题解决方法
- python3获取天气预报(转)
- urllib2 的使用细节(转)
- urllib2 的使用细节(转)
- urllib2的使用
- Python-urllib2的使用
- urllib/urllib2的使用
- urllib2的使用
- 合并真机和模拟器的SDK
- 考研党的寒假学习之spring+hibernate(2)
- 联系人侧边栏控件
- EXCEL为每行后添加一空行
- 代码审查清单
- 天气预报(Python3.4 re和urllib2的使用)
- 使用Cobbler无人值守安装CentOS
- android对象池之Message
- 将数据库中保存的时间戳转换为过去的时间格式
- VC6.0配置PROC开发环境
- BSCMAKE: error BK1505 cannot read from file 'Debug/XXX.bsc'
- DI(Dependency Inversion 依赖反转)
- MEX文件调试—MATLAB调用C++程序—混合编程
- WebKit的历史项管理