Created
December 10, 2015 04:27
-
-
Save xiangzhuyuan/38336a50bcd795ee1d38 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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