Google Search Results (SerpApi)

2.4.2 · maintenance · verified Sat Apr 11

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

Install

Imports

Quickstart

This quickstart demonstrates how to perform a basic Google search using the `google-search-results` library, fetching results for 'coffee' in Austin, Texas. It retrieves the SerpApi key from an environment variable for security and best practice.

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}")

view raw JSON →