python用re.findall获取网页全部符合要求的元素

如图,这是一段获取网页图片的代码,但是我不是要获取图片,最终目的是获取某一微博用户发布过所有微博的时间,微博时间的源代码是这样的:
<a class="time" target="_blank" href="http://t.qq.com/p/t/460317005393443" rel="1422203163" from="6">昨天 00:26</a>
即获取class=time的所有元素,请问各位大神,我应该怎么改图上的语句才能实现功能呢,谢!

关键在于查找时间的正则表达式,也就是程序中reg变量的字符串,你可以去了解一下

import re
s = """<a class="time" target="_blank" href="">昨天 00:26</a>
<a class="time" target="_blank" href="">今天 00:26</a>"""

def getTime(html):
   reg = r'<a class="time".*>(.*)</a>'
   timere = re.compile(reg)
   timelist = re.findall(timere,html)
   for t in timelist:
       print t
       
getTime(s)

温馨提示:答案为网友推荐,仅供参考
相似回答