如何编写 Python 正则表达式以获取网页中的所有锚点标签?
下面的代码提取给定字符串中的所有标签。
更多Python相关文章,请阅读: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)
输出
['<', '>', '<', '>']
下面的代码提取给定字符串中的所有标签。
更多Python相关文章,请阅读: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)
['<', '>', '<', '>']
极客教程