How to get Google search results in Python

Checked on 2026-11-19.

The official answer is Google's Custom Search JSON API, and its documentation now says it is closed to new customers and will be discontinued on January 1, 2027. Here is what is left: the official API if you already use it, what Google points new customers to, what happens when your own script fetches google.com/search, and an HTTP API that returns the organic results as JSON.

1. The Custom Search JSON API, if you already have it

This is Google's official way to get search results as JSON. It answers from a Programmable Search Engine, which Google describes as a search engine "for your website, your blog, or a collection of websites", so you create one first. A request needs three things: an API key, the search engine's ID (cx) and the search (q).

Python
import os
import requests

res = requests.get(
    "https://www.googleapis.com/customsearch/v1",
    params={
        "key": os.environ["GOOGLE_API_KEY"],
        "cx": os.environ["GOOGLE_SEARCH_ENGINE_ID"],  # your Programmable Search Engine
        "q": "best crm software",
    },
    timeout=30,
)
res.raise_for_status()
for item in res.json().get("items", []):
    print(item["title"])
    print(item["link"])
    print(item["snippet"])

Each result in items has a title, a link and a snippet. One request returns at most 10 results, and the API never returns more than the first 100 results of a search. Google's prices: 100 search queries per day for free, then $5 per 1000 queries, up to 10k queries per day.

Where it stops: for anyone new, before it starts. The overview page says: "The Custom Search JSON API is closed to new customers." And: "Existing Custom Search JSON API customers have until January 1, 2027 to transition to an alternative solution." The prices above apply "only to existing Custom Search JSON API customers until the service discontinuation on January 1, 2027". If you are starting today, this route is closed. If you depend on it, you have a date.

2. What Google points you to instead

The same notice names two things:

  • Vertex AI Search, which it calls "a favorable alternative for searching up to 50 domains". That is search over sites you choose, not over the whole web.
  • A "full web search solution", for which the notice gives a contact form "to express your interest in and get more information". The page shows no price and no documentation for it.

If you are building an AI application there is a third official route: Grounding with Google Search in the Gemini API, which lets a Gemini model answer from current web content and cite its sources.

Where it stops: none of the three hands you Google's ranked results for any search today. The first searches the domains you choose, the second starts with a form, and the third returns an answer written by a model.

3. Fetching google.com/search with your own script

The obvious thing to try is to request https://www.google.com/search?q=... and parse the HTML. Three things stand in the way, all three published by Google.

  • The robots.txt file. google.com/robots.txt has the line Disallow: /search for all crawlers.
  • The terms. Google's Terms of Service (the version effective July 30, 2026) list among the things you must not do: "using automated means to access content from any of our services in violation of the machine-readable instructions on our web pages (for example, robots.txt files that disallow crawling, training, or other activities)". Its spam policies name the practice: machine-generated traffic is "sending automated queries to Google", which "includes scraping results for rank-checking purposes or other types of automated access to Google Search conducted without express permission".
  • The block. Google's help page says that when a network "seems to be sending automated traffic to Google Search", you might get the message "Our systems have detected unusual traffic from your computer network", most likely with a reCAPTCHA. What it counts as automated traffic includes "Search scrapers" and "Use of software that sends searches to Google to find how a website or web page ranks on Google".

Where it breaks: at the block, and not only for you: the same help page says the message can reach everyone who shares the network that sent the searches. The HTML of the results page is not a documented format either, so a parser that works today can stop without notice. This guide does not cover getting around the block.

4. An HTTP API that returns the organic results

With Pipefetch a search is one GET request that returns the first page of results as JSON.

Python
import os
import requests

res = requests.get(
    "https://pipefetch.com/v1/google/search",
    params={"q": "best crm software", "country": "US", "lang": "en"},
    headers={"x-api-key": os.environ["PIPEFETCH_API_KEY"]},
    timeout=90,
)
if res.status_code == 404:
    print("Google has no results for this search")     # not charged
elif res.status_code == 502:
    print("Google refused this search, send it again")  # not charged
else:
    res.raise_for_status()
    data = res.json()["data"]
    for result in data["results"]:
        print(result["position"], result["title"])
        print(result["url"])
        print(result["description"])
    for related in data["relatedSearches"]:
        print("related:", related["query"])

Each result has its position, title, url, domain, description (the snippet) and, when Google shows one, a date. Google's operators, such as site: and intitle:, work in q. country and lang choose whose Google you get; without a country it is the United States. The reference lists every field.

Where it stops, and the list is long on purpose:

  • One request is the first page: about 10 organic results. There are no further pages.
  • It reads the light results page Google serves to clients without JavaScript, not the full page a desktop browser gets. Ads, AI Overview, People also ask, the featured snippet, the places block, top stories, the knowledge panel, videos and images are not included.
  • Results are for a country, not for a city, and for a visitor who is not signed in.
  • Google sometimes refuses a search. The request then answers 502 upstream_error, costs nothing and can be sent again.
  • It is not an official Google API, and Pipefetch is not affiliated with Google. The reading happens on Pipefetch's servers instead of yours, but it is still automated reading of a Google results page, which is what the policies quoted above are about. If you need a route Google itself supports, it is one of the first two.

A request costs 1 credit. A search without results (404) and a refused one (502) cost nothing. A new account has 100 free credits and needs no card, and most requests take 2 to 9 seconds.

Which one should you use?

SituationUse
You already call the Custom Search JSON APIKeep it until January 1, 2027, and plan the move now
Search over your own site or a set of domainsVertex AI Search, as Google's notice suggests
An AI application that needs answers with sourcesGrounding with Google Search in the Gemini API
The organic results of a search as JSON, todayAn HTTP API such as Pipefetch, knowing what it leaves out

Why results from an API differ from your browser

The Pipefetch endpoint returns the results for the country and interface language you ask for. A browser also uses the searcher's city and search history, and it gets Google's full page. A position read through the API is not necessarily the one on your own screen.

Try it with 100 free credits. No card needed. No scraper to build or maintain. Get an API key or read the docs.

Free tools for this

Every source

YouTube

Instagram

Websites

TikTok

Facebook

Threads

LinkedIn

App stores

Steam

X

Pinterest

Airbnb

Real estate

Keywords

Job boards

Eventbrite

Shopify stores

Public tenders

All guides