python-3.x - 如何优化我的 Python 反向图像搜索以限制到特定域?

标签 python-3.x django image google-image-search

我正在使用 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)
如果可能的话,有人如何将搜索细化到特定域?

最佳答案

您可以通过添加 site:domain.com 来限制对特定域的正常搜索。 .所以你可以在参数 q 中使用它您的 POST 请求:

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

关于python-3.x - 如何优化我的 Python 反向图像搜索以限制到特定域?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62786536/

相关文章:

java - 如何使用分水岭改进图像分割?

c++ - SDL_LoadBMP()成功,但窗口全黑

python - 如何在某些索引处反转和连接字符串?

python - 如何修复 Qtab 并在选项卡区域创建更多按钮和文本行

python-3.x - 如何在注册过程中获取多个谷歌凭据(Gmail API、Pub/Sub、联系人)

django - 初始数据夹具中的用户

regex - 如何用正则表达式查找*

python - Django 开发将 HttpResponses 记录到开发服务器

python - 尝试使用 django 美味馅饼发布时出现 404 错误

css - 如何将 SVG(或 CSS)中的图像转换为非平行四边形形状?