Open In App

Performing Google Search using Python code

Let’s say you are working on a project that needs to do web scraping but you don’t know websites on which scraping is to be performed beforehand instead you are required to perform a google search and then proceed according to google search results to a few websites. In that case, you need google search results for your different queries.

Installation 
google package has one dependency on beautifulsoup which needs to be installed first.  

pip install beautifulsoup4

Then install the google package  

pip install google

Required Function and its parameters 

Python codes on how to do a google search using python script

Example1: google_search.py  




try:
    from googlesearch import search
except ImportError:
    print("No module named 'google' found")
 
# to search
query = "Geeksforgeeks"
 
for j in search(query, tld="co.in", num=10, stop=10, pause=2):
    print(j)

Output: 

Let’s perform a google search manually and verify our result

 

Example 2: google_search.py 




try:
    from googlesearch import search
except ImportError:
    print("No module named 'google' found")
 
# to search
query = "A computer science portal"
 
for j in search(query, tld="co.in", num=10, stop=10, pause=2):
    print(j)

Output: 

 

Let’s perform a google search manually and verify our result

Reference: Google python package

 


Article Tags :