Created
June 15, 2018 13:04
-
-
Save hiroto3432/7ce5da620acdc7a28be48d2b47d2e8cd to your computer and use it in GitHub Desktop.
This file contains 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 'open-uri' | |
require 'nokogiri' | |
require 'csv' | |
url = 'http://ekikara.jp/newdata/ekijikoku/1720011/down1_17361011.htm' | |
charset = nil | |
html = open(url) do |f| | |
charset = f.charset | |
f.read | |
end | |
doc = Nokogiri::HTML.parse(html, nil,charset) | |
table = [] | |
doc.xpath('//td[@class="lowBg06"]').each do |node| | |
tex = node.css('span[@class="l"]').inner_text | |
if tex != "" then | |
table << [tex.to_i] | |
end | |
end | |
i = 0 | |
doc.xpath('//td[@class="lowBgFFF" or @class="lowBg12"]').each do |node| | |
tex = node.css('span[@class="ll"]').inner_text.scan(/.{1,#{2}}/) | |
tex.map{|v| table[i] << v.to_i} | |
i = i+1 | |
end | |
CSV.open("TimeTable.csv","w") do |line| | |
table.each|t| | |
line << t | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment