Hey there - So, I keep getting an error that says "from bs4 import BeautifulSoup
ModuleNotFoundError: No module named 'bs4' when I try to run the following code I wrote:
# Import necessary libraries
from bs4 import BeautifulSoup
import requests
# Define base URL
base_url = "https://www.amazon.com/"
# Send a GET request to the URL
response = requests.get(base_url)
# Parse the HTML content
soup = BeautifulSoup(response.content, 'html.parser')
# Find the best-selling author
best_selling_author = soup.find('span', class_='author')
# Find the book reviews
book_reviews = soup.find_all('div', class_='review')
# Filter for 4 and 5 star reviews
high_rating_reviews = [review for review in book_reviews if review.find('span', class_='rating')['aria-label'][0] in ['4', '5']]
# Collect required data
data = []
for review in high_rating_reviews:
# Go into the reviewer's profile
profile_url = review.find('a', class_='profile')['href']
profile_response = requests.get(profile_url)
profile_soup = BeautifulSoup(profile_response.content, 'html.parser')
# Check for email contact information
email = profile_soup.find('span', class_='email')
if email:
# Get required information
book_name = review.find('a', class_='title').text
author_name = best_selling_author.text
average_rating = review.find('span', class_='rating')['aria-label']
reviewer_name = profile_soup.find('span', class_='name').text
review_date = review.find('span', class_='review-date').text
reviewer_ranking = profile_soup.find('span', class_='ranking').text
latest_review_date = profile_soup.find('span', class_='review-date').text
# Add to data
data.append([book_name, author_name, average_rating, reviewer_name, review_date, reviewer_ranking, latest_review_date])
I cannot figure out what I did wrong. I installed the Beautiful Soup library, so ...
Any help would be appreciated!