如何編寫 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)
['<', '>', '<', '>']