본문 바로가기
프로그래밍 놀이터/Script(Python)

[ruby] download and parse to json

by 돼지왕왕돼지 2018. 4. 3.

[ruby] download and parse to json



require "rubygems"

require "json"

require "net/http"

require "uri"

 

uri = URI.parse("http://address")

 

http = Net::HTTP.new(uri.host, uri.port)

request = Net::HTTP::Get.new(uri.request_uri)

 

response = http.request(request)

 

if response.code == "200"

  result = JSON.parse(response.body)

  

  result.each do |doc|

    puts doc["id"] #reference properties like this

    puts doc # this is the result in object form    

    puts ""

    puts ""

  end

else

  puts "ERROR!!!"

end


Not that difficult :)






댓글0