Skip to content

Instantly share code, notes, and snippets.

@hiroto3432
Created June 15, 2018 13:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hiroto3432/7ce5da620acdc7a28be48d2b47d2e8cd to your computer and use it in GitHub Desktop.
Save hiroto3432/7ce5da620acdc7a28be48d2b47d2e8cd to your computer and use it in GitHub Desktop.
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