當前位置:編程學習大全網 - 網站源碼 - python用re.findall獲取網頁全部符合要求的元素

python用re.findall獲取網頁全部符合要求的元素

關鍵在於查找時間的正則表達式,也就是程序中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)

  • 上一篇:什麽是開源(開放源代碼)
  • 下一篇:請問通達軟件底部指標旁邊有壹排小等號和向下箭頭的指標是什麽?
  • copyright 2024編程學習大全網