Solutions Touch
← Back to all blogs

November 8, 2019

Automating Google search using python

By Uttkarsh Kabde

Automating Google search using python

Here we are going to get first google result in different tab directly using command prompt. We are going to use python in build library webbrowser and another library...

Hello programmers, today we are going to code this topic named Automating google search using python. In this tutorial we are simply going to perform google search using terminal and our program will open first 20 google hits in our default web browser (mine is Google Chrome)

So, before start coding for it, we should start with downloading dependencies for today’s program. So Start with downloading following dependency with pip command (Skip if already downloaded)

Note : We also require package webbrowser for this program but webbrowser is part of the python standard library, you don't have to install a separate package to use it because it comes bundled with your python installation.

  1. Google (pip install google)

 

After entering above command into terminal, it will get install on your system. After installation done lets start for coding:

 

Code:         

from google import search
import webbrowser
q = input("Enter your google query")
for url in search(q, stop=20):
    print(url)
    webbrowser.open_new_tab(url)

 

Start coding above code into terminal or simply copy it and paste into .py file or you can also download it from download button.

 

After executing above code, with stable connection it will take few seconds (or few minutes  depending on your internet speed) and will open first 20 google hits into  your desire search in different tabs like given below in sample image (To get different number of hits simply change stop=”Your Desired hits”).

result_google_20_tab

result_2_google_20_tab

 

As you can see here above the address bar, there are multiple tabs are got opened same as result shown in terminal. Here we done. Now try it with your self. if any problem persist feel free to comment below. Also you can comment new idea or concept which are in your mind. We will try to implement them as soon as possible.

Happy Coding…

performing google search using python code python google search scraper automate google search using selenium webdriver python python requests google search selenium python google search python documentation google it automation with python script search google google it automation with python python google search scraper python browser web browser coding web scraping scraping google result automate google result go