Google reverse image search using POST request

前端 未结 1 2081
[愿得一人]
[愿得一人] 2020-12-30 09:42

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

相关标签:
1条回答
  • 2020-12-30 10:05

    This is easy to do if you're happy to install the requests module. The reverse image search workflow currently consists of a single POST request with a multipart body to an upload URL, the response to which is a redirect to the actual results page.

    import requests
    import webbrowser
    
    filePath = '/mnt/Images/test.png'
    searchUrl = 'http://www.google.hr/searchbyimage/upload'
    multipart = {'encoded_image': (filePath, open(filePath, 'rb')), 'image_content': ''}
    response = requests.post(searchUrl, files=multipart, allow_redirects=False)
    fetchUrl = response.headers['Location']
    webbrowser.open(fetchUrl)
    

    Of course, remember that Google may decide to change this workflow at any point!

    0 讨论(0)
提交回复
热议问题