In my previous blog post, we can easily scrape Yelp Place results with SerpApi. Besides the information about the restaurant, Yelp review results are essential for businesses looking to understand customer sentiment and improve their services. Once you have a large amount of Yelp Reviews data, you can identify common complaints and trends, allowing your business to enhance customer satisfaction. You can also track your competitor's performance, revealing strengths and weaknesses in the market.
Review analysis can also support local SEO optimization by identifying relevant keywords. With the rise of AI, you can analyze user reviews and suggest the highest-rated restaurants based on user preferences. Yelp Reviews data is definitely valuable for your business, helping you make better decisions and improve long-term success.
Scraping Yelp Reviews is challenging, but you don't need to worry about this. SerpApi already provides a quality Yelp Reviews API for you. With a few lines of code, you can scrape Yelp Reviews from a restaurant. Let's see how it works.
Setting Up a SerpApi Account
SerpApi offers a free plan for newly created accounts. Head to the sign-up page to register an account and complete your first search with our interactive playground. When you want to do more searches with us, please visit the pricing page.
Once you are familiar with all the results, you can utilize SERP APIs using your API Key.
Scrape your first Yelp Reviews result with SerpApi
Head to the Yelp Reviews API from the documentation on SerpApi for details.
Let's collect all reviews for a top restaurant in Austin, Texas - Terry Black's Barbecue . The data contains: "user_name", "user_link", "comment", "date", "rating" and more. You can also scrape more information with SerpApi.
First, you need to install the SerpApi client library.
pip install google-search-results
Set up the SerpApi credentials and search.
from serpapi import GoogleSearch
import os, json, csv
params = {
'api_key': 'YOUR_API_KEY', # your serpapi api
'engine': 'yelp_reviews', # SerpApi search engine
'place_id': 'YZs1gNSh_sN8JmN_nrpxeA',
}
To retrieve Yelp Reviews Results for a query, you can use the following code:
results = GoogleSearch(params).get_dict()['reviews']
You can store Yelp Reviews Results JSON data in databases or export them to a CSV file.
import csv
results = GoogleSearch(params).get_dict()['reviews']
header = ["user_name", "user_link", "comment", "date", "rating"]
with open("yelp_reviews_results.csv", "w", encoding="UTF8", newline="") as f:
writer = csv.writer(f)
writer.writerow(header)
for item in results:
writer.writerow([item.get('user', {}).get('name'), item.get('user', {}).get('link'), item.get('comment', {}).get('text'), item.get('date'), item.get('rating')])
This example uses Python, but you can also use all your favorite programming languages like Ruby, NodeJS, Java, PHP, and more.
If you have any questions, please feel free to contact me.