如何編寫 Python 正則表示式以獲取網頁中的所有錨記標籤?
以下程式碼提取給定字串中的所有標籤
示例
import re rex = re.compile(r'[\<\>]') l = "this is text1 <a href='irawati.com' target='_blank'>hi</a> this is text2" print rex.findall(l)
輸出
['<', '>', '<', '>']
廣告
以下程式碼提取給定字串中的所有標籤
import re rex = re.compile(r'[\<\>]') l = "this is text1 <a href='irawati.com' target='_blank'>hi</a> this is text2" print rex.findall(l)
['<', '>', '<', '>']