Image Search by Image is uploading an image or specify an image URL to Google, Google searches the web for the information which is related to this image.
I used mechanize lib to simulate browser.
The code is as below
import socket;
import urllib2;
import mechanize
#Browser
br = mechanize.Browser()
#options
br.set_handle_equiv(True)
br.set_handle_gzip(True)
br.set_handle_redirect(True)
br.set_handle_referer(True)
br.set_handle_robots(False)
#Follows refresh 0 but not hangs on refresh > 0
br.set_handle_refresh(mechanize._http.HTTPRefreshProcessor(), max_time=1)
#debugging?
br.set_debug_http(True)
br.set_debug_redirects(True)
br.set_debug_responses(True)
#User-Agent (this is cheating, ok?)
br.addheaders = [('User-agent', 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.114 Safari/537.36')]
def searchGoogle():
google="http://images.google.com/searchbyimage?site=search&image_url="
url=google+"imageURL
br.open(url)
In Google returned content, there is a tag called "Best guess for this image". Google put the name of what it thinks the thing in the image should be. I use this method to name a large amount of un-named images automatically.
This is basic code, more details code should be written for exceptions.