title: How to fetch google search results links using selenium and python
body: <p>I am trying to fetch all the search results link and print it. The problem I found is I am not able to iterate using the xpath of the individual search results because</p>
  <blockquote>
  <p>elems = driver.find_elements_by_xpath('div[2]/div/div[1]/a')</p>
  </blockquote>
  <p>is one result and the next result's link is</p>
  <blockquote>
  <p>elems = driver.find_elements_by_xpath('div[3]/div/div[1]/a')</p>
  </blockquote>
  <p>The index value of div is what iterates throughout the results. Currently I am able to fetch only one link with the index value of div. I want to fetch all of the results and append it to a list for further processing. Help me out on this one</p>
  <pre><code>driver = webdriver.Chrome()
  driver.get('http://www.google.com')
  
  search_input = driver.find_element_by_name('q')
  search_input.send_keys('stackoverflow')
  search_input.send_keys(Keys.ENTER)
  results = []
  elems = driver.find_elements_by_xpath('div[2]/div/div[1]/a')
  for elem in elems:
      href = elem.get_attribute('href')
      print(href)
      results.append(href)
  </code></pre>