In my previous blog post, we can easily scrape basic information like title, link, rating, reviews... of local businesses from Yelp. Yelp also provides a lot more useful information when you visit the detail page. It will show all images, phone, address, popular drinks or foods...You can scrape review highlights, operating hours...
Obviously with more information, you can do your competitive analysis, what menu items are popular, how customers review them. Or you can build new lead generation by identifying businesses are lacking of websites, poor reviews, or benefit from social media. Beside that, you can build aggregated directories, do market research and trend analysis, improving local SEO, real estate and urban planning or automated recommendation system.
Same as previous blog post, we will use SerpApi Yelp Place API to quickly scraping Yelp Place results. Let's do it!
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 Place result with SerpApi
Head to the Yelp Place API from the documentation on SerpApi for details.
Let's find information from one of the best coffee shop "% Arabica" . The data contains: "name", "review", "rating", "price", "website", "phone", "address", "business_map" 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_place', # SerpApi search engine
'place_id': 'arabica-brooklyn',
}
To retrieve Yelp Place Results for a query, you can use the following code:
item = GoogleSearch(params).get_dict()['place_results']
You can store Yelp Place Results JSON data in databases or export them to a CSV file.
import csv
header = ["name", "reviews", "rating", "price", "website", "phone", "address", "business_map"]
with open("yelp_place_results.csv", "w", encoding="UTF8", newline="") as f:
writer = csv.writer(f)
writer.writerow(header)
writer.writerow([item.get('name'), item.get('reviews'), item.get('rating'), item.get('price'), item.get('website'), item.get('phone'), item.get('address'), item.get('business_map')])
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.