Javatpoint Logo
Javatpoint Logo

Google Search Packages using Python

In this tutorial, we will learn about Python's current Google search packages. We will discover the usage of the libraries of the most used Google search libraries. We will also learn about search queries over Google using Python code. Python provides many libraries for Google search, but their documentation is quite complex and poorly written. This tutorial will guide how to use the Google search libraries in a simple way.

Let's have an introduction to libraries.

Google Search

Google is the most popular and widely used search engine across the world. It unlocks the information from all corners of the internet within just a few milliseconds. Last 20 years, we have relied on the standard method to query information ranging from news articles to research topics. There are two big reasons to search the internet are -

  • Solving problems with the stack overflow
  • Data Mining

Data mining is examining large data sets to extract new information or insights. The method of mining data from the internet is known as web mining. Web mining can be divided into three parts - Web Content Mining, Web Usage Mining and Web Structure Mining.

The web mining preferred method of retrieving data was using a Google search to retrieve URLs for scraping purposes. For this article's purpose, we will focus only on the URL retrieval process for now.

To work with the google library, we need to install the google library. We will use the following example -

Now we will perform the essential search operation. For example, the company "Apple" and the topic "iPhone" retrieve news articles.


The above code will display all the URLs over Google related to Matrix. You can do the google search and verify the result manually. The above function takes the following arguments -

  • query - It is a string that we want to search over Google.
  • tld - It stands for the top-level domain, which means we want to search our result on or google, in or some other domain.
  • lang - It represents the language.
  • num - It displays the number of results we want.
  • start - The first result to retrieve.
  • stop - The last result to retrieve. If we pass None it will search forever.
  • pause - It shows the lapse to wait between HTTP requests. If the lapse is too short, Google can block the IP. Keeping significant lapses will slow your program, but it is a safe and better option.
  • Return - It iterates the found URLs. If the stop parameter is none the iterator will loop forever.

To understand the source code and more details of googlesearch library, you can visit the official repository.

Google API

Google API is a Python library used to perform google searches efficiently. It works similarly to the other google libraries; it scraps the data from Google.

Note - It is not recommended not to run multiple times since it involves scraping.

To install this library use the following command in the terminal.

Now, let's do some simple search using googlesearchapi.

Example -

Output -

[GoogleResult(name=Taylor Swift | description=taylor swift - willow (official music video) RsEZ.., GoogleResult(name=Taylor Swift - > wiki > Taylo.. 
description=Taylor Alison Swift (born December 13, 1989) is a.., 
GoogleResult(name=Taylor Swift (@taylorswift) * Instagram photos and vide.. 
description=142.1m Followers, 0 Following, 486 Posts - See In.., 
GoogleResult(name=Taylor Swift - Home | > ... > .. 
description=Taylor Swift. 70978350 likes * 788642 talking abo.., 
GoogleResult(name=Taylor Swift | > music > tay.. 
description=Not content to merely be a country superstar, Tay.., 
GoogleResult(name=Taylor Swift: Evermore review - a songwriter for the ag.. 
description=10 hours ago -- Swift is a songwriter for the ages.., 
GoogleResult(name=Taylor Swift on > artist description=Taylor Swift, Category: Artist, Albums: evermore,..]

The googleapi prompts not only the source link but also appends the result with name and description as well. According to the developers, this library is in a development phase; more features are yet to come.

Currency Conversion

The googlesearchapi also allows us to convert the currency. It means, we can use the currency converter through the Python code. Let's understand the following example -

Example -


5.0 USD = 397.55 rupees

You can try with the other currencies.


This tutorial includes the two essential libraries for the google search APIs. Using these API, we can search the query using the Python code. You are free to explore these libraries and use them according to the requirements. This tutorial's motive is to familiarize you with the google search library.

Youtube For Videos Join Our Youtube Channel: Join Now


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Trending Technologies

B.Tech / MCA