How to create a simple google search in python
First of all fire up the terminal and check whether python3 is installed
Required libraries to perform google search in python
4.bs4 (Beautiful Soup)
If any of these libraries are not installed do the following
If you had python3 then the command to install these packages are
pip3 install requests
pip3 install sys
pip3 install webbrowser
pip3 install bs4
Uses of these libraries:
Requests library is to request the search url from the user
sys.argv is a list in Python, which contains the command-line arguments passed to the script.
webbrowser is used to display the requested information to the user in the browser
Beautiful Soup is a Python library for pulling data out of HTML and XML file
for i in range(linkToOpen):
1.Import all the required libraries which are mentioned above
2.Then request the user to input the search term in the command line argument so that we have used sys.argv to get the input in the command line.
3.This line checks the status of the search term and the result produced
4.This line initiates Beautiful soup which is retrieve all the html and xml files associated with the search term from the resultant sites.
6.This line tells how many link to open for the search term.You can any number of links to open for your search term.
7.Then loop over all the resultant links and then display it in the browser using the webbrowser library.
If you run the program by specifying the search term by
Python filename.py “search term”