Jul-20-2018, 10:40 PM
This is web scraping project from Automate the Boring Stuff with Python. From some reason solution doesn't work and I have some doubts myself. The goal is to type a search term on the command line and have my computer automatically open a browser with all the top search results in new tabs.
I'm also not sure how to start this program. Should I type a search term in command prompt where I usually start my python files?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
#! python3 # lucky.py - Opens several Google search results. import webbrowser, bs4, requests, sys print ( 'Googling...' ) # display text while downloading the Google page print (res.raise_for_status()) # Retreive top search result links. soup = bs4.BeautifulSoup(res.text, "html.parser" ) # Open a browser tab for each result linkElems = soup.select( '.r a' ) numOpen = min ( 5 , len (linkElems)) for i in range (numOpen): |