title: Google reverse image search using POST request
body: <p>I have an app that's basically a database of images stored on my local drive. Sometimes I need to find a higher resolution version or the web source of an image, and Google's <a href="https://www.google.hr/imghp?sbi=1" rel="noreferrer">reverse image search</a> is ideal for that. </p>
  
  <p>Unfortunately, Google doesn't have an API for it, so I had to figure out a way to do it manually. Right now I'm using Selenium, but that obviously has a lot of overhead. I'd like a simple solution using urllib2 or something similar - send a POST request, get the search URL back, and then I can just pass that URL to <code>webbrowser.open(url)</code> to load it in my already opened system browser.</p>
  
  <p>Here's what I'm using right now:</p>
  
  <pre><code>gotUrl = QtCore.pyqtSignal(str)
  filePath = "/mnt/Images/test.png"
  
  browser = webdriver.Firefox()
  browser.get('http://www.google.hr/imghp')
  
  # Click "Search by image" icon
  elem = browser.find_element_by_class_name('gsst_a')
  elem.click()
  
  # Switch from "Paste image URL" to "Upload an image"
  browser.execute_script("google.qb.ti(true);return false")
  
  # Set the path of the local file and submit
  elem = browser.find_element_by_id("qbfile")
  elem.send_keys(filePath)
  
  # Get the resulting URL and make sure it's displayed in English
  browser.get(browser.current_url+"&amp;hl=en")
  try:
      # If there are multiple image sizes, we want the URL for the "All sizes" page
      elem = browser.find_element_by_link_text("All sizes")
      elem.click()
      gotUrl.emit(browser.current_url)
  except:
      gotUrl.emit(browser.current_url)
  browser.quit()
  </code></pre>