ruby 中的特定 api 搜索图像对我不起作用
a specific api that search imagen in ruby didn t work to me
我正在尝试获取此 api 的响应:
here is some documentation of the api
所以当我尝试调用 api 时,控制台会给我以下信息:
web_1 | #<Unirest::HttpResponse:0x000055ac03684818 @code=200,@headers={:d
ate=>"Sat, 23 Jun 2018 06:17:30 GMT", :server=>"Microsoft-IIS/8.5", :cache_contr
ol=>"no-cache", :pragma=>"no-cache", :content_length=>"29", :content_type=>"appl
ication/json; charset=utf-8", :expires=>"-1", :x_aspnet_version=>"4.0.30319", :x
_powered_by=>"ASP.NET"}, @raw_body=<RestClient::Response 200 "{\"_type\":\"i..."
>, @body={"_type"=>"images", "value"=>[]}>
但是如果你看到图像的 url 所在的“值”,它是空的,我不知道为什么,这是我的代码:
require 'json'
require 'unirest'
response = Unirest.get "http://contextualwebsearch.com/api/Search/ImageSearchAPI?q=donald%20trump&count=10&autoCorrect=true"
puts response.inspect
所有这一切的罕见之处在于,如果您访问此页面:
http://contextualwebsearch.com/api/Search/ImageSearchAPI?q=donald%20trump&count=10&autoCorrect=true 您会找到包含我正在搜索的所有信息的 json。
您可以使用rest-client
require 'net/http'
require 'json'
require 'rest-client'
res = RestClient.get("http://contextualwebsearch.com/api/Search/ImageSearchAPI?q=donald%20trump&count=10&autoCorrect=true")
body = JSON.parse(res, { symbolize_names: true })
puts body[:value]
也 Unirest
工作正常
require 'json'
require 'unirest'
response = Unirest.get "http://contextualwebsearch.com/api/Search/ImageSearchAPI?q=donald%20trump&count=10&autoCorrect=true"
puts response.body["value"]
我正在尝试获取此 api 的响应:
here is some documentation of the api
所以当我尝试调用 api 时,控制台会给我以下信息:
web_1 | #<Unirest::HttpResponse:0x000055ac03684818 @code=200,@headers={:d
ate=>"Sat, 23 Jun 2018 06:17:30 GMT", :server=>"Microsoft-IIS/8.5", :cache_contr
ol=>"no-cache", :pragma=>"no-cache", :content_length=>"29", :content_type=>"appl
ication/json; charset=utf-8", :expires=>"-1", :x_aspnet_version=>"4.0.30319", :x
_powered_by=>"ASP.NET"}, @raw_body=<RestClient::Response 200 "{\"_type\":\"i..."
>, @body={"_type"=>"images", "value"=>[]}>
但是如果你看到图像的 url 所在的“值”,它是空的,我不知道为什么,这是我的代码:
require 'json'
require 'unirest'
response = Unirest.get "http://contextualwebsearch.com/api/Search/ImageSearchAPI?q=donald%20trump&count=10&autoCorrect=true"
puts response.inspect
所有这一切的罕见之处在于,如果您访问此页面: http://contextualwebsearch.com/api/Search/ImageSearchAPI?q=donald%20trump&count=10&autoCorrect=true 您会找到包含我正在搜索的所有信息的 json。
您可以使用rest-client
require 'net/http'
require 'json'
require 'rest-client'
res = RestClient.get("http://contextualwebsearch.com/api/Search/ImageSearchAPI?q=donald%20trump&count=10&autoCorrect=true")
body = JSON.parse(res, { symbolize_names: true })
puts body[:value]
也 Unirest
工作正常
require 'json'
require 'unirest'
response = Unirest.get "http://contextualwebsearch.com/api/Search/ImageSearchAPI?q=donald%20trump&count=10&autoCorrect=true"
puts response.body["value"]