Skip to content

Instantly share code, notes, and snippets.

@Aayush-N
Last active February 8, 2018 12:23
Show Gist options
  • Save Aayush-N/0aa8327ef6e0734959685520840940d6 to your computer and use it in GitHub Desktop.
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
#! 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