Using Google Custom Search API with Python

Google APIs are like superpowers for developers. They’re a set of tools that let you tap into the magic of Google’s services and add their capabilities to your own projects. Think of them as a treasure trove of functions and data that you can use to create awesome applications. Google Custom Search Json API lets us use Google’s search engine in our own projects. Think of it like adding Google search to your apps!. This Article is about using Google Custom Search Api with Python.

Steps to use Google Custom Search API

To use the Google Custom Search API with Python, follow these steps:

  1. Enable the Google Custom Search API:
    • Go to the Google Cloud Console.
    • Create a new project or select an existing project.
    • Navigate to the “APIs & Services” > “Library” section.
    • Search for “Google Custom Search JSON API” and enable it.
  2. Create Credentials:
    • After enabling the API, go to the “APIs & Services” > “Credentials” section.
    • Click “Create Credentials” and select “API key”.
    • Follow the prompts to create and obtain your API key.
  3. Get Search Engine Id:
    • Go to the Programmable Search Engine Dashboard
    • Create a New Search Engine
    • Name your Search Engine
    • Select “Search Entire Web Results”
    • Click Create
    • Click on Customize, and copy Search Engine Id (Referred as cx)
  4. Install Libraries:
    • Install the requests library to make HTTP requests in Python.
  5. Make API Requests:
    • Use your API key to authenticate your requests to the Google Custom Search API.
    • Construct the API request URL with the appropriate parameters.
import requests #pip install requests
apiKey= 'Your API Key'
cx = 'Your Search Engine Id'
query = input("Enter Your Query: ")
url = f'{baseUrl}?key={apiKey}&cx={cx}&q={query}&startIndex=11'
response = requests.get(url)
if response.status_code==200:
    data = response.json()
    for item in data['items']:

Detailed Video on Using Google Custom Search API with Python is Here:

Leave a Comment