How to Create a Simple Web Scraper using BeautifulSoup

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]}")

Leave a Comment

Your email address will not be published.