title: BeautifulSoup.select Method
body: <p>This script is suppose to take command line string and run it through the google search engine and then if results are found it will open up the first 5 in different tabs. I am having some issues trying to get it to work. I think the problem is happening towards the bottom where it says <code>link = soup.select(".r a")</code>, I have been altering the values here and then it will show the next line with an actual length. But running it like this shows the length to still be 0. I am trying to scrape the .r class and a tag because that seems to be where the searched results start on the google result source code. </p>
  
  <pre><code>import requests
  import bs4
  import sys
  import webbrowser
  
  print("Googling...")
  response = requests.get("https://www.google.com/#q=" + " ".join(sys.argv[1:]))
  response.raise_for_status()
  
  '''Function to return the top search result links'''
  soup = bs4.BeautifulSoup(response.text, "html.parser")
  
  '''Open a browser tab for each result'''
  links = soup.select(".r a")
  print(len(links))
  numOpen = min(5, len(links))
  
  for i in range(numOpen):
      webbrowser.open("https://google.com/#q=" + links[i].get("href"))
  </code></pre>