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.
- Google (pip install google)
After entering above command into terminal, it will get install on your system. After installation done lets start for coding:
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”).
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.