I want to develop a map application which will display the banks near a given place.
I use the Places library to search and everytime it just return 20 results. What should I do if I want more results?
I want to develop a map application which will display the banks near a given place.
I use the Places library to search and everytime it just return 20 results. What should I do if I want more results?
You can scrape Google Places results and follow pagination to get 200-300 places for a specific location (from 10 to 15 pages of search results).
Alternatively, you can use SerpApi to access extracted data from Google Places. It has a free trial.
# Package: https://pypi.org/project/google-search-results
from serpapi import GoogleSearch
import os
params = {
"api_key": os.getenv("API_KEY"),
"engine": "google",
"q": "restaurants",
"location": "United States",
"tbm": "lcl",
"start": 0
}
search = GoogleSearch(params)
data = search.get_dict()
for local_result in data['local_results']:
print(
f"Position: {local_result['position']}\nTitle: {local_result['title']}\n"
)
while ('next' in data['serpapi_pagination']):
search.params_dict["start"] += len(data['local_results'])
data = search.get_dict()
print(f"Current page: {data['serpapi_pagination']['current']}\n")
for local_result in data['local_results']:
print(
f"Position: {local_result['position']}\nTitle: {local_result['title']}\n"
)
Output
Current page: 11
Position: 1
Title: Carbone
Position: 2
Title: Elmer's Restaurant (Palm Springs, CA)
Position: 3
Title: The Table Vegetarian Restaurant
...
Disclaimer: I work at SerpApi.