Python Forum
Project: “I’m Feeling Lucky” Google Search - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Web Scraping & Web Development (https://python-forum.io/forum-13.html)
+--- Thread: Project: “I’m Feeling Lucky” Google Search (/thread-11674.html)

Pages: 1 2 3 4


RE: Project: “I’m Feeling Lucky” Google Search - MoreOvaltinePlease - Jul-04-2019

I've been through this whole thread and everything in my code is working (running the exact code from this thread), except my browser won't launch with search results - here is my output when I run my .py script, which indicates success (code 200). Apologies, I'm probably missing something super obvious here - maybe I'm missing what should be run from cmd?

Output:
= RESTART: C:\Users\plenn\AppData\Local\Programs\Python\Python37-32\lucky.py = Hi! Please add search term: NHL NHL Googling... url: http://google.com/search?q=N H L 200 >>>



RE: Project: “I’m Feeling Lucky” Google Search - tab_lo_lo - Jul-09-2019

Man, I'm having trouble with this project too. I'm getting no search results after passing the search terms into the run window. Here's my code:
#! python3
# lucky.py - Opens several Google search results.
 
import webbrowser, bs4, requests, sys
 
print('Googling...') # display text while downloading the Google page
res = requests.get('http://google.com/search?q=' + ' '.join(sys.argv[1:]))
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):
    webbrowser.open('http://google.com' + linkElems[i].get('href'))