Created
November 25, 2023 15:52
-
-
Save kashaziz/48c8ca6996ac32e9c143db3231864c54 to your computer and use it in GitHub Desktop.
Product review sentiment analysis using python
This file contains 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
""" 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