This script takes a keyword(s), searches it on Google and then opens up tabs of the results in the browser. The script returns an empty array at the select
method and I'm confused as to why. I checked the HTML of the search results and the CSS selector seems like it should work.
#! /usr/bin/env python3
import webbrowser, sys, requests, bs4, pyperclip
if len(sys.argv) > 1:
address = ' '.join(sys.argv[1:])
else:
address = pyperclip.paste()
res = requests.get('https://www.google.com/search?q=' + address)
soup = bs4.BeautifulSoup(res.text, "lxml")
linkElems = soup.select('.r a')
numOpen = min(5, len(linkElems))
for i in range(numOpen):
webbrowser.open('http://google.com' + linkElems[i].get('href'))