mizuho_bank

A library for accessing Mizuho Direct (Mizuho Bank’s internet banking) from Ruby. It automates the login page flow (customer number → security questions → password) with Mechanize, letting you pull account balances and transaction statements out as Ruby objects.

It was published as a gem at the time. In an era with no API, it was a scraper for handling your own account data programmatically.

gem install mizuho_bank

Usage looks like this (from the README). It is designed to load credentials from Pit, an account-information manager, rather than hard-coding them.

require 'mizuho_bank'
require 'pit'

pit = Pit.get("MizuhoBank", :require => {
  "keiyaku_no" => "keiyaku_no",
  "password" => "password",
  # 合言葉(秘密の質問)3組の question/answer も同様に登録しておく
})

aikotoba_dict = {
  pit['aikotoba1_question'] => pit['aikotoba1_answer'],
  pit['aikotoba2_question'] => pit['aikotoba2_answer'],
  pit['aikotoba3_question'] => pit['aikotoba3_answer']
}

MizuhoBank.new(pit['keiyaku_no'].to_s, pit['password'].to_s, aikotoba_dict){ |bank|
  p bank.info.main_account.money        # 口座残高
  p bank.info.main_account.cache_flows  # 最近の取引履歴
}

Internals

Component layout. The core MizuhoBank class ties together the login handling and page parsing, and results are returned packed into plain data classes: MizuhoDirectInfo / MizuhoAccount / MizuhoCacheFlow.

Component diagram of mizuho_bank

The flow from login through fetching statements.

Sequence diagram of mizuho_bank’s login and statement retrieval

As a known issue, the image CAPTCHA demanded after repeated security-question failures is not supported (noted in the README). Also, since the parsing is tightly coupled to the page wording and table structure, this is the kind of code that breaks whenever the site is redesigned.