Python Google Search Scraper

3.0.0 · active · verified Thu Apr 09

This library provides Python bindings for performing web searches on Google.com by directly scraping the search results pages. It is important to note that this is NOT an official Google product or API. Its functionality relies on parsing the HTML structure of Google's search results, making it highly susceptible to breaking changes if Google alters its website layout. Users should be aware of potential rate limiting and IP blocking from Google.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to perform a basic Google search using the `search` function. It includes a `pause` parameter to mitigate the risk of IP blocking from Google, which is a common issue with web scraping libraries.

import time
from google import search

search_query = "checklist.day Python libraries"

print(f"Searching for: '{search_query}'")

# Perform a search for 5 URLs, with a 2-second pause between requests
# to avoid IP blocking. Adjust parameters as needed.
try:
    for i, url in enumerate(search(search_query, tld="com", lang="en", num=5, start=0, stop=5, pause=2.0)):
        print(f"Result {i+1}: {url}")
except Exception as e:
    print(f"An error occurred: {e}")
    print("Consider increasing the 'pause' time or checking your network connection.")

view raw JSON →