首页 > 解决方案 > 如何优化我的 Python 反向图像搜索以限制到特定域?

问题描述

我正在使用 Python 3.8。我有以下用于启动 Google 反向图像搜索的脚本...

    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)

如果可能的话,有谁可以将搜索细化到特定域?

标签: python-3.xdjangoimagegoogle-image-search

解决方案


您可以通过添加site:domain.com. 因此,您可以在qPOST 请求的参数中使用它:

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

推荐阅读