Google Search Results (SerpApi)
The `google-search-results` Python package (version 2.4.2) is a client library designed to scrape and parse localized search results from various engines like Google, Bing, Baidu, Yahoo, Yandex, eBay, and more, by utilizing the SerpApi.com service. While functional, it is now considered a 'legacy' SerpApi module, with the actively maintained and recommended client being the `serpapi` package. Its last update was March 2023.
Warnings
- breaking The `google-search-results` package is considered a legacy wrapper for SerpApi. The official and actively maintained Python client is now the `serpapi` package (pip install serpapi), which offers more features and better support.
- gotcha Despite being installed as `google-search-results`, the primary class is imported from the `serpapi` namespace (`from serpapi import GoogleSearch`). This can cause confusion with the newer, separate `serpapi` package.
- gotcha Always manage your SerpApi key securely using environment variables (e.g., `SERPAPI_API_KEY`) instead of hardcoding it in your scripts.
- gotcha SerpApi uses standard HTTP response codes. Unsuccessful requests will raise `serpapi.HTTPError` or `serpapi.TimeoutError` exceptions (from the underlying `serpapi` library components or the new `serpapi` client). Common errors include 401 (Unauthorized - invalid API key), 429 (Too Many Requests - rate limit or out of searches).
- deprecated As of September 2025, SerpApi discontinued support for the Google Product API endpoint. Users scraping product page views should migrate to the Google Immersive Product API.
- gotcha SerpApi accounts have daily usage limits. Exceeding these limits can result in `429 Too Many Requests` errors or your account running out of searches.
Install
-
pip install google-search-results
Imports
- GoogleSearch
from serpapi import GoogleSearch
Quickstart
import os
from serpapi import GoogleSearch
# Ensure your SerpApi key is set as an environment variable, e.g., SERPAPI_API_KEY
api_key = os.environ.get('SERPAPI_API_KEY', '')
if not api_key:
print("Error: SERPAPI_API_KEY environment variable not set.")
else:
params = {
"q": "coffee",
"location": "Austin, Texas",
"hl": "en",
"gl": "us",
"api_key": api_key
}
try:
search = GoogleSearch(params)
results = search.get_dict()
if 'organic_results' in results:
for result in results['organic_results']:
print(f"Title: {result.get('title')}\nLink: {result.get('link')}\n")
else:
print("No organic results found.")
except Exception as e:
print(f"An error occurred: {e}")