python 正则获取html中的值
2015-08-21 15:57
316 查看
# -*- coding: utf-8 -*- from BeautifulSoup import BeautifulSoup import re def get_timestamp(html): soup = BeautifulSoup(html) authi_elems = soup.findAll('div', { 'class': 'authi' }) for authi_elem in authi_elems: date_elem = authi_elem.find('span', title=re.compile(r'20\d{2}-\d+-\d+\s\d{2}:\d{2}:\d{2}')) print date_elem.get('title') if __name__ == '__main__': html = """ <div class="authi"> <img class="authicn vm" id="" src="static/image/common/online_member.gif" /> <em id="">发表于 <span title="2013-4-2 08:30:11">4 天前</span></em> <span class="pipe">|</span><a href=>倒序浏览</a> <div style="float:right;position:relative;top:-6px;"><ul> <li style="float: left; width: 130px; height: 24px;"><wb:follow-button uid="" type="gray_2" width="136" height="24"></wb:follow-button></li> <li style=" float:left; width: 160px; height: 24px;"></li> </ul></div></div> """ get_timestamp(html)
相关文章推荐
- python从入门到精通走过的路
- python中的dict
- python 中几个层次的中文编码.md
- R语言和Python语言访问MySQL数据库
- 如何安装python gensim
- 详解Python的切片(Slice)
- Python中类、实例和类方法、静态方法、实例方法的关系
- python 基础环境配置
- Python yield 使用浅析
- word2vec纯程序+注释
- python模块
- opencv3.0+python3.4编译
- vijos - P1077克隆龙 (找规律 + 指数型母函数 + python)
- Python中for循环和while循环的基本使用方法
- python基础之使用os.system来执行系统命令
- windows下 OpenCV 2.x.x Python 2.7.x配置
- python常用的数据分析工具包
- 【Python】输出程序执行的百分比
- python基础三——面向对象
- python的二进制文件读写