Created
July 2, 2019 12:35
-
-
Save aambrioso1/253940849352df4c89c7df9337e7021b to your computer and use it in GitHub Desktop.
webbrowsertest.py
This file contains hidden or 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
# import webbrowser | |
# import requests, os, bs4 | |
# webbrowser.open('http://inventwithpython.com/') | |
#! python3 | |
# lucky.py - Opens 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 top search result links. | |
soup = bs4.BeautifulSoup(res.text) | |
# Open a browser tab for each result. | |
linkElems = soup.select('.r a') | |
numOpen = min(5, len(linkElems)) | |
print(numOpen) | |
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