How to use Python Regular expression to extract URL from an HTML link?

PythonServer Side ProgrammingProgramming

The following code extracts the url from a html link using python regex

Example

import re
s = '''http://www.santa.com'''
match = re.search(r'href=[\'"]?([^\'" >]+)', s)
if match:
    print match.group(0)

Output

This gives the output

href="http://www.santa.com"
raja
Published on 11-Jan-2018 14:11:29
Advertisements