Skip to content

Instantly share code, notes, and snippets.

@kashaziz
Created November 25, 2023 15:52
Show Gist options
  • Save kashaziz/48c8ca6996ac32e9c143db3231864c54 to your computer and use it in GitHub Desktop.
Save kashaziz/48c8ca6996ac32e9c143db3231864c54 to your computer and use it in GitHub Desktop.
Product review sentiment analysis using python
""" Perform sentiment analysis on product reviews of Amazon product """
import requests
from bs4 import BeautifulSoup
from textblob import TextBlob
def analyze_product_reviews(url):
response = requests.get(url)
soup = BeautifulSoup(response.content, 'html.parser')
reviews = soup.find_all('div', {'data-hook': 'review-collapsed'})
for review in reviews:
text = review.text
sentiment = TextBlob(text).sentiment
print(f"Review: {text}")
print(f"Sentiment: {sentiment}")
if __name__ == '__main__':
url = 'https://amzn.to/3uz7Sk8'
analyze_product_reviews(url)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment