Skip to content

Instantly share code, notes, and snippets.

@reefwing
Created March 26, 2023 00:57
Show Gist options
  • Save reefwing/eb13623bfa5ddc34261726fd3f768db2 to your computer and use it in GitHub Desktop.
Save reefwing/eb13623bfa5ddc34261726fd3f768db2 to your computer and use it in GitHub Desktop.
import requests
from bs4 import BeautifulSoup
# Send a request to the website and get its content
response = requests.get("http://quotes.toscrape.com")
content = response.content
# Parse the content with BeautifulSoup
soup = BeautifulSoup(content, "html.parser")
# Find all the quote and author elements on the page
quotes = []
for quote in soup.find_all("div", class_="quote"):
text = quote.find("span", class_="text").text
author = quote.find("small", class_="author").text
quotes.append({"quote": text, "author": author})
# Print the list of quotes
print(quotes)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment