Created
January 31, 2009 03:26
-
-
Save darashi/55420 to your computer and use it in GitHub Desktop.
http://www.sapica.jp から SAPICA 利用履歴を取得するスクリプト
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
#!/usr/bin/env ruby1.9 | |
require 'rubygems' | |
require 'pit' | |
require 'nokogiri' | |
require 'mechanize' | |
config = Pit.get('sapica', :require => { | |
'cardid' => 'your card id', | |
'password' => 'your password' | |
}) | |
agent = WWW::Mechanize.new | |
page = agent.get('https://www.sapica.jp/Login/') | |
form = page.forms.first | |
form.cardid = config['cardid'] | |
form.password = config['password'] | |
page = form.submit | |
history = [] | |
doc = Nokogiri::HTML(page.body) | |
table = doc.xpath("//table[@id='historytable']") | |
table.xpath('tr').each do |tr| | |
nodes = tr.xpath('td') | |
rows = nodes.map{|r|r.text.sub(/^(?:\s|\xc2\xa0)+/,'')} | |
history << rows unless rows.empty? | |
end | |
history.each do |h| | |
[4,5].each {|i| h[i].gsub!(',', '')} | |
puts h.join(',') | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment