import requests
from bs4 import BeautifulSoup
import csv
def scrape_google_reviews(url):
# Send a GET request to the review link
source_code = requests.get(url)
plain_text = source_code.text
# Parse the HTML content using BeautifulSoup
soup = BeautifulSoup(plain_text, 'html.parser')
# Extract all review containers
review_containers = soup.find_all('div', class_='section-review-content')
# Create a CSV file to store the scraped data
csv_file = open('google_reviews.csv', 'w', newline='', encoding='utf-8')
writer = csv.writer(csv_file)
writer.writerow(['Reviewer', 'Rating', 'Date', 'Review'])
# Loop through each review container and extract the required information
for container in review_containers:
reviewer = container.select_one('div[class*="section-review-title"]').text.strip()
rating = container.find('span', class_='section-review-stars')['aria-label']
date = container.select_one('span[class*="section-review-publish-date"]').text.strip()
review = container.select_one('span[class*="section-review-text"]').text.strip()
# Write the extracted data to the CSV file
writer.writerow([reviewer, rating, date, review])
csv_file.close()
# Specify the URL of the Google Map review link
review_url = 'https://www.google.com/maps/place/Your_Place/reviews'
# Call the scrape_google_reviews function with the specified URL
scrape_google_reviews(review_url)