Python Forum
Project: “I’m Feeling Lucky” Google Search
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Project: “I’m Feeling Lucky” Google Search
#31
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 >>>
Reply
#32
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'))
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  With Selenium create a google Search list in Incognito mode withe specific location, tsurubaso 3 3,185 Jun-15-2020, 12:34 PM
Last Post: tsurubaso
  "I'm Feeling Lucky" script problem (again) tab_lo_lo 7 7,715 Jul-23-2019, 11:26 PM
Last Post: snippsat
  How to use BeautifulSoup to parse google search results DevinGP 16 21,176 Dec-22-2017, 10:23 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020