Last active
February 6, 2016 14:47
-
-
Save itkq/fb2bde3a5a76f73fa8c3 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 'dotenv' | |
require 'mechanize' | |
Dotenv.load | |
mech = Mechanize.new | |
mech.user_agent_alias = 'Windows IE 7' | |
url = 'https://web.ib.mizuhobank.co.jp/servlet2/CASBNK60000B.do' | |
page = mech.get(url) | |
if page.form.nil? | |
puts 'System maintenance now.' | |
exit | |
end | |
page.form do |f| | |
f.txbBrnchNo = ENV['BRANCH_NO'] | |
f.txbAccNo = ENV['ACCOUNT_NO'] | |
f.PASSWD_LoginPwd = ENV['PASSWORD'] | |
f.radiobutton_with(:value => '001').check | |
end.submit | |
articles = mech.page.search('article').to_a | |
account_info = history_info = nil | |
articles.each do |a| | |
text = a.text.strip | |
if text.match(/^口座情報/) | |
account_info = a | |
elsif text.match(/^入出金明細/) | |
history_info = a | |
end | |
end | |
print "\n" | |
(account_info/'tr').each do |tr| | |
head = (tr/'th').text.chomp | |
body = (tr/'td').text.chomp | |
puts "#{head} : #{body}" | |
end | |
puts "[取引履歴]" | |
puts mech.page.search('th.ctr').map{|th| th.text}.join("\t") | |
(history_info/'td').each do |td| | |
id = td.children.first.attr('id') | |
delimiter = id.match('txtTransCntnt') ? "\n" : "\t" | |
print "#{td.text}#{delimiter}" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment