script   0   1790
Python Script 4: Opening top 10 Google search result in one hit

This is the fourth script in 'Python Scripts' series.

You can have a look at previous scripts by following the links given below.

Python Script 3: Validate and format JSON string
Python Script 2: Crawling all emails from a website
Python Script 1: Convert ebook from one format to another

As the title suggest, this script is used to open top 10 Google search results in different tabs for provided keyword.



Code:

"""
Author: Anurag Rana
Usage: python google.py <keyword>
Description: Script googles the keyword and opens top 10(max) search results in separate tabs in the browser
Usage: python filename.py keyword
Tested with Python3
"""

import webbrowser
import sys
import pyperclip
import requests
import bs4


def start():
	if len(sys.argv) > 1:
		keyword = ' '.join(sys.argv[1:])
	else:
		# if no keyword is entered, the script would 
		# search for the keyword copied in the clipboard
		keyword = pyperclip.paste()

	res = requests.get('https://google.com/search?q='+keyword)
	soup = bs4.BeautifulSoup(res.text,'lxml')
	links = soup.select('.r a')
	tab_counts = min(10, len(links))

	for i in range(tab_counts):
		webbrowser.open('https://google.com' + links[i].get('href'))


start()
 

I am using this same concept at my work. Every day I have to open 8 applications (slack, JIRA, gitlab, Facebook :p, stackoverflow, Jenkins UI, Outlook and Personal Email) in my browser. So instead of opening each application one by one, I just run the script and all these applications are opened in different tabs saving few seconds :D.

script   0   1790

Related Articles:
Python Script 13: Generating ascii code from Image
Generating ascii art from image, converting colored image to ascii code, python script to convert image to ascii code, python code to generate the ascii image from jpg image....
Python Script 1: Convert ebooks from epub to mobi format
Python script to convert the ebooks from one format to another in bulk. Automated book conversion to kindle format. Free kindle ebook format conversion....
Python Script 8: Validating Credit Card Number - Luhn's Algorithm
Validating credit card number using Luhn' Algorithm, Verifying Credit and Debit card using python script, Python code to validate the credit card number, Luhn' algorithm implementation in Python...
Python Script 9: Getting System Information in Linux using python script
Finding linux system information like processor details, memory usage and average load using python script. Python program to find Ubuntu information....

0 thoughts on 'Python Script 4: Opening Top 10 Google Search Result In One Hit'
Leave a comment:


*All Fields are mandatory. **Email Id will not be published publicly.


SUBSCRIBE
Please subscribe to get the latest articles in your mailbox.


Recent Posts:






© pythoncircle.com 2018-2019
Contact Us: code108labs [at] gmail.com
Address: 3747 Smithfield Avenue, Houston, Texas