You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
19 lines
622 B
19 lines
622 B
#! python3 |
|
# lucky.py - open several Google search results |
|
|
|
import requests, sys, webbrowser, bs4 |
|
|
|
print('Googling...') # display text while downloading the Google page |
|
res = requests.get('http://google.com/search?q=' +''.join(sys.argv[1:])) |
|
res.raise_for_status() |
|
|
|
# retrieve the top search result links |
|
soup = bs4.BeautifulSoup(res.text, 'html.parser') |
|
|
|
# open a browser tab for each |
|
linkElems = soup.select('.LC201b h3') |
|
numOpen = min(5, len(linkElems)) |
|
print('Opening {} links.'.format(numOpen)) |
|
for i in range(numOpen): |
|
webbrowser.open('http://google.com' + linkElems[i].get('href')) |
|
linkElems[i].get('href')
|
|
|