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
#28
In the meantime I made it:

#! python3
# lucky1.py - Opens several Google search results.
  
import webbrowser
import bs4 
import requests
import sys

def my_func(search_str):
    print('Googling...') # display text while downloading the Google page
    url = 'http://google.com/search?q=' + ' '.join(search_str)
    print(f'url: {url}')
    res = requests.get(url)
    print(res.status_code)
  
    # Retreive top search result links.
    soup = bs4.BeautifulSoup(res.text, "html.parser")
  
    # Open a browser tab for each result
    linkElems = soup.select('.r a')
    for link in linkElems:
        print(f'link: {link}')
    numOpen = min(5, len(linkElems))
    for i in range(numOpen):
        webbrowser.open('http://google.com' + linkElems[i].get('href'))
 
def test_it(args):
    print(args)
    my_func(args)
  
if __name__ == '__main__':
    client = input("Hi! Please add search term: ")
    test_it(client)
Reply


Messages In This Thread
RE: Project: “I’m Feeling Lucky” Google Search - by Truman - Jul-29-2018, 10:08 PM

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,398 Jun-15-2020, 12:34 PM
Last Post: tsurubaso
  "I'm Feeling Lucky" script problem (again) tab_lo_lo 7 7,977 Jul-23-2019, 11:26 PM
Last Post: snippsat
  How to use BeautifulSoup to parse google search results DevinGP 16 21,781 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