When you start a new business, how can you approach your clients? Having a targeted list of potential clients can make your life simpler.
In this tutorial, we can run a case when you want to get 500 restaurants, bars, pubs, alongside a location with website and phone information.
More than that, I'll guide you on how to get emails and you can send your cold mail to gain a success rate.
Scraping quality results is not easy, but SerpApi makes it easier and more accessible to us. Let's start with Google Maps results.
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 results, you can utilize SERP APIs using your API Key.
Scrape your first 60 Restaurant results with SerpApi
Head to the Google Maps Results from the documentation on SerpApi for details.
This tutorial will scrape the list of restaurants in Sydney, Australia. You can visit Google Maps search to see the list.
Link: https://www.google.com/maps/search/restaurant/@-33.8651304,151.1939402,15z?entry=ttu
The location will be @-33.8651304,151.1939402,15z (Townhall, Sydney, Australia).
Google also returns basic information of businesses:
When searching with SerpApi, you can have them all:
Based on Google policy, Google doesn't publish the email of the business. But most of the time, we can visit the restaurant's website and get contact information. For e.g, I visit https://swillhouse.com/venues/restaurant-hubert/
Let's do this step by step.
First, you need to install the SerpApi client library.
pip install google-search-results
Set up the SerpApi credentials and search.
import serpapi, os, json
params = {
'api_key': 'YOUR_API_KEY', # your serpapi api
'engine': 'google_maps', # SerpApi search engine
'q': 'Restaurant',
'll': '@-33.8651304,151.1939402,15z'
}
To retrieve a list of Restaurants, you can use the following code:
results = serpapi.Client().search(params)["local_results"]
You can store Restaurant JSON data in databases or export them to a CSV file.
import csv
header = ['position', 'title', 'place_id', 'address', 'website', 'phone']
with open('google_maps_results.csv', 'w', encoding='UTF8', newline='') as f:
writer = csv.writer(f)
writer.writerow(header)
for item in results:
print(item)
writer.writerow([item.get('position'), item.get('title'), item.get('place_id'), item.get('address'), item.get('website'), item.get('phone')])
No-code approach with SerpApi
If you don't want to code, SerpApi also has a Google Sheet Plugin, you just need to input your SerpApi api_key and you get your results:
Clone this Google Sheet template: https://docs.google.com/spreadsheets/d/1OXqATnTahjNCJ3MJ9D2If1GU5eVZiljYOIyLv72bADc/edit#gid=1524491998
Then install our Google Sheet plugin:
Update the SerpApi "api_key"
In the next blog post, I'll guide you on how to get email addresses, contact information, social media links, and extra phone numbers from here.
If you have any questions, please feel free to contact me.