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 google search and then proceed according to google search result to few websites. In that case you need google search result for your different queries.
- One way of achieving this is using request and beautiful soup which has been discussed here in Implementing Web Scraping in Python with BeautifulSoup.
- Instead of putting so much effort for a trivial task google package has been made. Its almost a one liner solution to find links of all the google search result directly.
- Using python package google we can get result of google search from python script. We can get link of first n search results.
Installation
google package has one dependency on beautifulsoup which need to be installed first.
pip install beautifulsoup4
Then install google package
pip install google
Required Function and its parameters
search(query, tld='com', lang='en', num=10, start=0, stop=None, pause=2.0)
- query : query string that we want to search for.
- tld : tld stands for top level domain which means we want to search our result on google.com or google.in or some other domain.
- lang : lang stands for language.
- num : Number of results we want.
- start : First result to retrieve.
- stop : Last result to retrieve. Use None to keep searching forever.
- pause : Lapse to wait between HTTP requests. Lapse too short may cause Google to block your IP. Keeping significant lapse will make your program slow but its safe and better option.
- Return : Generator (iterator) that yields found URLs. If the stop parameter is None the iterator will loop forever.
Python codes on how to do 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:
Lets perform 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:
Lets perform google search manually and verify our result

Referecne : Google python package
This article is contributed by Pratik Chhajer. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.
Recommended Posts:
- Create a GUI to search bank information with IFSC Code using Python
- Python | Get a set of places according to search query using Google Places API
- Python | Automate Google Search using Selenium
- Search Google Using Python Selenium
- Scrape Google Search Results using Python BeautifulSoup
- Python | Get a google map image of specified location using Google Static Maps API
- How to run Python code on Google Colaboratory
- Download Anything to Google Drive using Google colab
- Performing BVA Testing using Pytest
- Python - Performing operations on the stock data
- Find the longest common prefix between two strings after performing swaps on second string
- Python | Generate QR Code using pyqrcode module
- Debugging Python code using breakpoint() and pdb
- Issues with using C code in Python | Set 1
- Issues with using C code in Python | Set 2
- Python code formatting using Black
- Convert Python Code to a Software to Install on Windows Using Inno Setup Compiler
- Python - Morse Code Translator GUI using Tkinter
- Application to get address details from zip code Using Python
- Wi-Fi QR Code Generator Using Python

