關鍵在於查找時間的正則表達式,也就是程序中reg變量的字符串,妳可以去了解壹下
import?res?=?"""<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)