Created
March 26, 2023 00:57
-
-
Save reefwing/eb13623bfa5ddc34261726fd3f768db2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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