【问题标题】:Ruby reverse image search on Yandex using rest-client file upload使用 rest-client 文件上传在 Yandex 上进行 Ruby 反向图像搜索
【发布时间】:2021-03-14 01:30:46
【问题描述】:

我正在尝试在 ruby​​ 中克隆此堆栈溢出问题的最佳答案

Reverse search an image in Yandex Images using Python

require 'rest-client'
require 'pry'

response =  RestClient.post 'https://yandex.com/images/search', 
            proxy: 'http://1.1.1.1:8080',
            params: {rpt: 'imageview', format: 'json', request: '{"blocks":[{"block":"b-page_type_search-by-image__link"}]}'}, 
            :upload => File.new("/home/alex/Desktop/yandex_search/t2.jpg", 'rb'),
            multipart: true
            
binding.pry

我无法上传文件。不断得到回应 "Yandex.Images 中空请求的搜索结果"

【问题讨论】:

    标签: ruby rest-client yandex


    【解决方案1】:

    根据 python 实现,参数看起来应该作为查询参数发送。

    告诉 RestClient 将其作为查询参数发送的方法是使用 headers 参数中的 params 值。

    require 'rest-client'
    
    query_strings =  {rpt: 'imageview', format: 'json', request: '{"blocks":[{"block":"b-page_type_search-by-image__link"}]}'}
    
    RestClient.proxy = "http://1.1.1.1:8080"
    
    result = RestClient.post(
      "https://yandex.com/images/search",
      {:upfile => File.new("/home/alex/Desktop/yandex_search/t2.jpg", 'rb')},
      {params: query_strings, multipart: true}
    )
    

    【讨论】:

    • 这是正确的,只需要将响应本身作为 JSON 获取,它就像 reponse = JSON.parse(result), image_link = response["blocks"][0]["参数"]["url"]
    猜你喜欢
    • 2020-09-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-09-01
    • 1970-01-01
    • 2020-09-12
    • 1970-01-01
    • 2012-12-02
    相关资源
    最近更新 更多