python-3.xdjangoimagegoogle-image-search

How can I refine my Python reverse image search to limit to a specific domain?


I'm using Python 3.8. I have the following script for launching a Google reverse image search ...

    filePath = '/tmp/cat_and_dog.webp'
    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)

Does anyone how, if possible, I can refine the search to a specific domain?


Solution

  • You can restrict normal searches to a particular domain by adding site:domain.com. So you can use that in a parameter q of your POST request:

    domain = 'wikipedia.org'
    multipart = {'encoded_image': (filePath, open(filePath, 'rb')), 'image_content': '', 
        'q': f'site:{domain}' }