Skip to content

Instantly share code, notes, and snippets.

@xiangzhuyuan
Created December 10, 2015 04:27
Show Gist options
  • Select an option

  • Save xiangzhuyuan/38336a50bcd795ee1d38 to your computer and use it in GitHub Desktop.

Select an option

Save xiangzhuyuan/38336a50bcd795ee1d38 to your computer and use it in GitHub Desktop.
require 'faraday'
require 'json'
connection = Faraday.new('http://www3.nhk.or.jp') do |builder|
builder.request :url_encoded
builder.response :logger
builder.adapter Faraday.default_adapter
end
begin
response = connection.get('/news/easy/news-list.json')
body = response.body.encode('utf-8', {invalid: :replace, undef: :replace, replace: ''})
json = JSON.parse(body)
# puts json
json.each do |item|
item.each_with_index do |day, news|
puts day
puts news
end
end
rescue => e
puts e.message
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment