Javatpoint Logo
Javatpoint Logo

Performing Google Search using Python Code

Web Scraping is a process of scraping webpages and extracting details from them. Instead of regularly copying and pasting information from the web pages for a project, web scraping can be effective for this problem. But, there are few websites available for web scraping. There are different solutions for this problem:

  • Using the selenium and beautifulSoup package provided by Python. These packages are used by which we can scrape the web pages with the help of drivers.
  • Another efficient and easy method for this problem is to find all the links of the Google search simultaneously with one click. This can be possible using the Google package provided by Python. Using this package, we will get all the links to the results.

More about google package in Python

Python provides an API named Google API, which performs Google searches easily and accurately. Like BeautifulSoup, it is also used to scape the data from Google.

Installing google package in Python

As it also depends on the BeautifulSoup, we need to install the BeautifulSoup package in Python.

The module used in the google package is googlesearch. The function used in the googlesearch module to search for web pages and retrieve the URLs is search( ).

Syntax of the search function in Python is:

Functions and Parameters in google API in Python

  • lang: it stands for Language.
  • num: it defines the number of results we want to search.
  • query: It is the string we want to search.
  • TLD: It stands for top-level domain. It defines the domain on which we want to search our results, like,, etc.
  • start: It defines the first result which is to be searched.
  • stop: It defines the last result to be searched. We can perform an unlimited search by keeping the stop value as None.
  • return: It defines the iterator that gives the search results in the form of URLs. It can iterate forever if the stop parameter is kept as None.
  • pause: It defines the lapse while waiting between the HTTP requests. Google can block IP addresses if there are short lapses.

Let's understand the google API by implementing it in Python.

Program 1: A simple search using google API in Python




Firstly, we have imported the google package. Then, we have given the query as javatpoint. Using the search function, we have set the values of different parameters to search the query. We have taken tld as, the total number of searches as 12, the stop value as 20, i.e., it will give 20 URLs, and the lapse time as 2.

Program 2: Searching an article on the google package using Python




We have searched the article "Uses of Data Science" using the google module in Python. We have set the total number of searches as 14 and the stop value as 25, giving 25 results. We have taken the lapse of 4, which takes more time to search.

Program 3: Infinite searching with google API in Python


Output: ....


In this, we have searched the topic "Basic skills for data science" using the google package in Python. We have set the stop value as None. It means it will give infinite searches. It gives all the possible searches related to the query.

We can check the results by searching the query on the google itself. We will get the same results as the output by the google API.

Python is such a versatile language that it offers us functions and modules that help to search from search engines like Google directly from the code. With the help of these APIs and libraries, it gives way to automation, scraping, data extraction, etc.

Youtube For Videos Join Our Youtube Channel: Join Now


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Trending Technologies

B.Tech / MCA