Extracting labels using regex

We can use regex package to identify common patterns such as emails and URLs. With BeautifulSoup, you can specify regular expression patterns to match specific tags. In this script, we are extracting email addresses that match a specific pattern.

You can find the following code in the extract_emails_from_url.py file inside the beautifulSoup folder:

import requests
import re
from bs4 import BeautifulSoup

url = input("Enter the URL: ")
response = requests.get(url)
html_page = response.text
email_pattern=re.compile(r'[w.-]+?@w+?.w+?')

for match in re.findall(email_pattern,html_page):
print(match)
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset