Created
June 19, 2025 00:32
-
-
Save hilmanski/933bee4a3cad075a7b371df373f5bc04 to your computer and use it in GitHub Desktop.
scrape review on Google Maps Reviews API by SerpApi
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
SERPAPI_API_KEY = "YOUR_API_KEY" | |
# data_id= "0x87c0efbfabd07121:0x4d29f6c1222606e7" # thousand reviews | |
# data_id = "0x2dbee30bfa8faf9b:0x7bda5e20f02979af" # 10-100 | |
# data_id = "0x2dbefd34f300372b:0x5427dc086be165c4" # 100-1000 | |
# data_id = "0x2dbf1d8302c0b94f:0x83758d60d4c55557" #212 reviews | |
data_id = "0x2dbf02a197360ef1:0x2d1688ef40474288" #473 reviews | |
params = { | |
"api_key": SERPAPI_API_KEY, | |
"engine": "google_maps_reviews", | |
"data_id": data_id, | |
"sort_by": "newestFirst", | |
} | |
search = requests.get("https://serpapi.com/search", params=params) | |
response = search.json() | |
current_page = 0 | |
total_reviews = len(response["reviews"]) | |
actual_total_place_reviews = response["place_info"]["reviews"] | |
print(f"Total reviews first page: {total_reviews}") | |
if "serpapi_pagination" in response: | |
next_page_token = response["serpapi_pagination"].get("next_page_token") | |
while next_page_token: | |
params["next_page_token"] = next_page_token | |
params["num"] = 20 | |
# run the search with the updated parameters | |
search = requests.get("https://serpapi.com/search", params=params) | |
response = search.json() | |
if "reviews" not in response: | |
print("No reviews found in the response.") | |
break | |
total_reviews += len(response["reviews"]) | |
print(f"Page {current_page + 1} reviews: {total_reviews}") | |
current_page += 1 | |
if not response.get("reviews"): | |
print("No more reviews found.") | |
break | |
if "serpapi_pagination" not in response: | |
print("No more pages to fetch.") | |
break | |
next_page_token = response.get("serpapi_pagination", {}).get("next_page_token") | |
print(f"Total reviews fetched: {total_reviews}") | |
print(f"Actual total place reviews: {actual_total_place_reviews}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment