想获取html中time用python正则如何实现,timepython,想做一个爬虫,使用Bea
想获取html中time用python正则如何实现,timepython,想做一个爬虫,使用Bea
想做一个爬虫,使用BeautifulSoup假使获取以下内容:
<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>
如何获取以上内容中的2013-4-2 08:30:11这个时间呢?
我试着写了一个
re.compile('^20\d{2}-\d+-\d+\s\d{2}:\d{2}:\d{2}')
可是这个在使用的时候不能匹配到时间?如何解决?谢谢!
re.compile('20\d{2}-\d+-\d+\s\d{2}:\d{2}:\d{2}')
https://gist.github.com/greatghoul/53...
# -*- coding: utf-8 -*-from BeautifulSoup import BeautifulSoup import redef 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 split函数内参数的具体作用,pythonsplit,str = server
- python numpy deep copy相关问题,pythonnumpy,在列表中,b=a[:
- 请问rc.local配置uwsgi启动不正常,rc.localuwsgi,操作系统:
- Python3.4怎样进入子目录语法是什么?,python3.4语法,比如
- 《Python核心编程》书中关于type的不解,,type(a)== ty
- Python WEB网页selenium截图不完整有什么解决方案吗,pyt
- Flask Web第6章 电子邮件 error: [Errno 111] Connection refused,
- 关于Python函数的一段代码,求大神帮检查下代码问题,
- Python Ubuntu直接播放url链接mp3歌曲用什么库,pythonubunt
- Python程序员有尝试在Android平台设备做开发工作的吗?,
评论关闭