Last active
February 8, 2018 12:23
-
-
Save Aayush-N/0aa8327ef6e0734959685520840940d6 to your computer and use it in GitHub Desktop.
Opens multiple tabs with top Google Search links for the given text
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! python3 | |
# luckySearch.py - Opens several google search results | |
import requests, sys, webbrowser, bs4 | |
search = input("Enter the text to be searched: ") | |
print('Googling...') | |
res = requests.get('http://google.com/search?q=' + ' '.join(search)) | |
res.raise_for_status() | |
print('downloaded') | |
#TODO Retrieve top search results | |
soup = bs4.BeautifulSoup(res.text) | |
print('retrieved into a file') | |
#TODO open a web browser tab for each search result | |
linkElems = soup.select('.r a') | |
numOpen = min(5, len(linkElems)) | |
for i in range(numOpen): | |
webbrowser.open('http://google.com' + linkElems[i].get('href')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment