Skip to content

Instantly share code, notes, and snippets.

@swdevbali
Created May 16, 2023 09:20
Show Gist options
  • Save swdevbali/aa2e099d53f3b46ab5f535cbd7052b72 to your computer and use it in GitHub Desktop.
Save swdevbali/aa2e099d53f3b46ab5f535cbd7052b72 to your computer and use it in GitHub Desktop.
# regex_soup.py
import re
from urllib.request import urlopen
url = "http://olympus.realpython.org/profiles/dionysus"
page = urlopen(url)
html = page.read().decode("utf-8")
pattern = "<title.*?>.*?</title.*?>"
match_results = re.search(pattern, html, re.IGNORECASE)
title = match_results.group()
title = re.sub("<.*?>", "", title) # Remove HTML tags
print(title)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment