Computer >> Computer tutorials >  >> Programming >> Python

How to write Python regular expression to get all the anchor tags in a webpage?


The following code extracts all tags in the given string

Example

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)

Output

['<', '>', '<', '>']