import requests from bs4 import BeautifulSoup url = 'https://www.example.com' response = requests.get(url) soup = BeautifulSoup(response.text, 'html.parser') titles = soup.find_all('h2') print(f"Titles from {url}:\n{[title.text.strip() for title in titles]}")