Google Search Python Library

1.3.0 · active · verified Sun Apr 12

googlesearch is a Python library for scraping the Google search engine. It uses `requests` and `BeautifulSoup4` to parse Google's search results. The library is actively maintained with releases addressing changes in Google's search page structure. The current version is 1.3.0, released January 21, 2025.

Warnings

Install

Imports

Quickstart

Performs a Google search for a given query and prints the top 5 unique URLs. It demonstrates how to use the `pause` parameter to prevent IP blocking and includes a commented section for retrieving `advanced` search results with titles and descriptions.

from googlesearch import search

query = "latest Python news"

# The 'pause' parameter helps avoid IP blocks from Google by adding a delay between requests.
# 'num_results' specifies how many unique URLs to return.
results = list(search(query, num_results=5, lang="en", pause=2))

if results:
    print(f"Top 5 results for '{query}':")
    for i, url in enumerate(results):
        print(f"{i+1}. {url}")
else:
    print(f"No results found for '{query}'.")

# To get more detailed information (title, URL, description), use 'advanced=True'
# from googlesearch import search, SearchResult
# adv_results = list(search(query, advanced=True, num_results=3, pause=2))
# if adv_results:
#     print("\nAdvanced search results:")
#     for i, res in enumerate(adv_results):
#         print(f"{i+1}. Title: {res.title}")
#         print(f"   URL: {res.url}")
#         print(f"   Description: {res.description}")

view raw JSON →