0

I'm making a basic "I'm feeling lucky" Python application but when I try to select the link, it returns nothing.

import requests, webbrowser, bs4, sys

print('Googling...')
res = requests.get('https://google.com/search?q=%s' % sys.argv[1])

if res.status_code != 200:
    print('Invalid input')
    sys.exit()

res = res.text
soup = bs4.BeautifulSoup(res, features='html.parser')

search = soup.select('.r') # trying to select the class "r"
print(search) # returns "[]"

1 Answers1

0

This happens because Google sends a redirect page, not a result page. This prevents the system from working.

randomuser5215
  • 508
  • 1
  • 9
  • 26