Hurry! Try our new Interactive Courses for FREE. 🥳   🚀
  Signup/Sign In
Written By:
6 minute read

How to Perform Google Search using Python

Posted in Programming   LAST UPDATED: AUGUST 18, 2021

If you want to develop a search service utilizing the power of Google search, you can do so using the google module in Python. You can use this to develop a backend service for a desktop application or implement a website search or app search with the python code running on your server.

Perform Google search using Python

If you are a Python beginner, then you can learn Python from Studytonight.

You can do the same using the BeautifulSoup module too which is used for web scraping in Python. But the google module makes it super simple to implement search.

Installing Google module

To install the google module, we can use the pip package installer.

pip install google

This will install the google module, along with its other dependencies. The name of the module installed is googlesearch.

We will be using the search() function from the googlesearch module.

search(query, tld='', lang='en', num=10, start=0, stop=None, pause=2)
  • query: This is the text that you want to search for.

  • tld: This refers to the top level domain value like or com which will specify which Google website we want to use.

  • lang: This parameter stands for language.

  • num: This is used to specify the number of results we want.

  • start: This is to specify from where to start the results. We should keep it 0 to begin from the very start.

  • stop: The last result to retrieve. Use None to keep searching forever.

  • pause: This parameter is used to specify the number of seconds to pause between consecutive HTTP requests because if we hit too many requests, Google can block our IP address.

The above function will return a python generator (iterator) which has the search result URLs.

Perform Google Search

Now let's use the google module to perform search.

from googlesearch import search

query = "studytonight"

for i in search(query, tld="", num=10, stop=10, pause=2):

In the above output you can see the links that will be shown on Google search if you open the Google search website and search for "studytonight" text.

Similarly, you can search for any text, and can even change the tld parameter to search for results in different Google websites.


Well, that's it for this tutorial. Try using this python code to get search results from google programmatically. While using this code, do not name the python file as as that can cause conflict with the module.

You may also like: