Skip to main content

googlesearch

googlesearch lets you use Google Searching capabilities right from your Python code or from your CLI

Make any Google Search right from Python!

PyPI version PyPI - Downloads PyPI - Python Version PyPI - Status GitHub - License GitHub top language CodeQL Checks Badge Pytest Code Size Repo Size Issues

Getting Started

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system.

Prerequisites

You will need Python 3 to use this module

# vermin output
Minimum required versions: 3.2
Incompatible versions:     2

According to Vermin, Python 3.2 is needed

Always check if your Python version works with googlesearch before using it in production

Installing

Option 1: From PyPI

pip install python-googlesearch

Make sure to download python-googlesearch as googlesearch cannot be given to any package on PyPI

Even if you download python-googlesearch, googlesearch is used for the imports and the CLI version for conveniency purposes

Option 2: From Git

pip install git+https://github.com/Animenosekai/googlesearch

You can check if you successfully installed it by printing out its version:

$ python -c "import googlesearch; print(googlesearch.__version__)"
# output:
googlesearch v1.1.1

or just:

$ googlesearch --version
# output:
googlesearch v1.1.1

Usage

You can use googlesearch in Python by importing it in your script:

>>> from googlesearch import Search
>>> python_results = Search("Python")
>>> python_results.results
[<SearchResult title="Python.org" (www.python.org)>, <SearchResult title="Python" ()>, <SearchResult title="Python (langage) — Wikipédia" (fr.wikipedia.org › wiki › Python_(langage))>, ...]

CLI usage

You can use googlesearch in other apps by accessing it through the CLI version:

$ googlesearch --query Python
{
    "query": "Python",
    "results": [
        {
            "url": "https://www.python.org/",
            "title": "Welcome to Python.org",
            "displayedURL": "www.python.org",
            "description": "The official home of the Python Programming Language.\nDownloads \u00b7 Python For Beginners \u00b7 Quotes about Python \u00b7 Python Essays"
        },
        [...]
    ],
    "relatedSearches": [
        "Python serpent",
        "Python openclassroom",
        [...]
    ],
    "success": true
}

Interactive Shell (REPL)

An interactive version of the CLI is also available

$ googlesearch
Enter '.quit' to exit googlesearch
[?] (googlesearch ~ Query) > : ... # enter your query

[?] What do you want to do?: # select the result with your keyboard's arrows and [enter]

—————————————————SEARCH RESULT—————————————————
[...] # site's name

Description: # the site's description
URL: ... # site's URL
Related Searches: # a max of 3 related searches

You can get help on this version by using:

$ googlesearch --help
usage: googlesearch [-h] [--version] [--query QUERY] [--langua...

As a Python module

Search

The search class represents a Google Search.

It lets you retrieve the different results/websites (Search.results) and the related searches (Search.related_searches)

How to use

This class is lazy loading the results.

When you initialize it with Search(), it takes a query as the required parameter and the following parameters as optional parameters:

  • language: The language to request the results in (All of the website won't be in the given language as it is biased by lots of factors, including your IP address location). This needs to be a two-letter ISO 639-1 language code (default: "en")
  • number_of_results: The max number of results to be passed to Google Search while requesting the results (This won't give you the exact number of results) (default: 10)
  • retry_count: A positive integer representing the number of retries done before raising an exception (useful as googlesearch seems to fail sometimes) (default: 3)
  • parser: The BeautifulSoup parser to use (default: "html.parser")

It will only load and parse the website when results or related_searches is called.

parser is the BeautifulSoup parser used to parse the website and .

results is a list of googlesearch.models.SearchResultElement.

related_searches is a list of Search elements.

SearchResultElement

This class represents a result and is initialized by googlesearch.

It holds the following information:

  • url: The URL of the website
  • title: The title of the website
  • displayed_url: The URL displayed on Google Search
  • description: The description of the website

Extra

Every class has the as_dict function which converts the object into a dictionary. For Search, the as_dict function will convert the other Search objects in related_search to a string with the query.

Exceptions

All of the exceptions inherit from the GoogleSearchException exception.

You can find a list of exceptions in the exceptions.py file

Deployment

This module is currently in development and might contain bugs.

Feel free to use it in production if you feel like it is suitable for your production even if you may encounter issues.

Built With

Authors

License

This project is licensed under the MIT License - see the LICENSE file for more details

Metadata

Release files for python-googlesearch 1.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for python-googlesearch 1.1.1
File Size Uploaded
python-googlesearch-1.1.1.tar.gz 12.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for python-googlesearch 1.1.1
File Interpreter ABI Platform
python_googlesearch-1.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 24.3 kB

Release files / python-googlesearch-1.1.1.tar.gz

Download URL python-googlesearch-1.1.1.tar.gz
Size 12.3 kB
Tags Source
SHA-256 checksum
How to use checksums
23bfe1d07399443d4abbedf13a22790dce0bf4bf06e7256f9ede9f6deaba9d4f
BLAKE2b-256 checksum
How to use checksums
f9051032ea13e2e7fc820f946b05c2ebdf8f1b875194b3734a98e8b8535e133a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/4.6.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.9.5

Release files / python_googlesearch-1.1.1-py3-none-any.whl

Download URL python_googlesearch-1.1.1-py3-none-any.whl
Size 12.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
af7c1c829dc990c5b898d71aa8688afb151b3d8debaf674e0f71a8c6761f890f
BLAKE2b-256 checksum
How to use checksums
0ca61578e5ac476e28b9c6929538ce47822431b0572138e9e96a6281a3429c75
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/4.6.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.9.5

Release history Release notifications | RSS feed

This release

1.1.1 This release

2 release files

1.1.0

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page