import requests # For sending HTTP requests from bs4 import BeautifulSoup # For parsing HTML import pandas as pd # For data manipulation and storage
product_url = "https://www.flipkart.com/product-name/reviews"
response = requests.get(product_url)
if response.status_code == 200: # Parse the HTML content of the page using BeautifulSoup soup = BeautifulSoup(response.text, 'html.parser')
# Locate the review container element
review_container = soup.find('div', class_='review-container')
for review in review_container.find_all('div', class_='review'):
# Extract review details such as reviewer name, rating, date, and text
reviewer_name = review.find('div', class_='reviewer-name').text
rating = review.find('div', class_='rating').text
review_date = review.find('div', class_='review-date').text
review_text = review.find('div', class_='review-text').text
# Store the extracted data in a dictionary or data frame
else: # Handle the case when the request fails print("Failed to retrieve the web page. Status code:", response.status_code)