Created
July 5, 2014 21:10
-
-
Save takuya/7f4d7703e56f0d43f6c9 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 'mechanize' | |
# トップページ | |
m = Mechanize.new | |
m.follow_meta_refresh = true | |
m.get "http://www.jibunbank.co.jp/" | |
## ログインURL | |
m.page.link_with( :text=> /ログイン/).click | |
match = m.page.body.strip.split(/\n/).grep(/.*RetailLogin.html.*/).first.match /\"(RetailLogin.html.*)\"/ | |
path = match[1] | |
login_uri = URI.join(m.page.uri.to_s, path).to_s | |
## ログインフォーム 表示 | |
m.get login_uri | |
## ログイン送信 | |
form = m.page.forms.find{|e| e.fields_with(:type=>"password").size == 1 } | |
form.field_with( :type => /pass/ ).value= password | |
form.field_with( :name => /fldLoginUserCRN1/ ).value = login_id[0] | |
form.field_with( :name => /fldLoginUserCRN2/ ).value = login_id[1] | |
form.submit | |
## クッションページ処理 | |
appId = m.page.body.split(/\n/).grep(/var appId/).first.match(/\"(.*)\"/)[1] | |
def_txnId = m.page.body.split(/\n/).grep(/def_txnId/).first.match(/\"(.*)\"/)[1] | |
sessionId = m.page.body.split(/\n/).grep(/sessionId/).first.match(/\"(.*)\"/)[1] | |
def_scrnSeqNbr= m.page.body.split(/\n/).grep(/def_scrnSeqNbr/).first.match(/\"(.*)\"/)[1] | |
frmPost = m.page.form_with( :name => /frmPost/) | |
frmPost.field_with( :name => /fldAppId/ ).value = appId | |
frmPost.field_with( :name => /fldAppId/ ).value = appId | |
frmPost.field_with( :name => /fldTxnId/ ).value = def_txnId | |
frmPost.field_with( :name => /fldSessionId/).value = sessionId | |
frmPost.field_with( :name => /fldScrnSeqNbr/).value = def_scrnSeqNbr | |
frmPost.submit() | |
## トップページ保存 | |
top_page = m.page.clone | |
## 出入金明細 | |
a = m.page.link_with :text =>/入出金明細/ | |
args = a.attributes["onclick"].scan(/'[^']+'/)[1,3].map{|e| e.gsub(/'/,"")} | |
frmMenu = m.page.form_with( :name => /frmMenu/) | |
frmMenu.field_with( :name=> /fldTxnId/ ).value = args[0] | |
frmMenu.field_with( :name=> /fldAppId/ ).value = args[1] | |
frmMenu.submit() | |
# 出入金明細ページ保存 | |
meisai_page = m.page.clone | |
## トップページ保存 | |
["#menu", "#banner","#news", "script", "*[class^=footer]", "p.btn", "#copyright","p.info", ".buttonBox", "table.search", "#selectSearch", ".post > p"].each{|selector| | |
top_page.search(selector).remove if top_page.search(selector).size>0 | |
meisai_page.search(selector).remove if meisai_page.search(selector).size>0 | |
} | |
require 'base64' | |
sub_mech = Mechanize.new() | |
css = "" | |
sub_mech.get "https://bk02.jibunbank.co.jp/ibretail/smartphone/css/reset.css" | |
css = css + "\n" + sub_mech.page.body | |
sub_mech.get "https://bk02.jibunbank.co.jp/ibretail/smartphone/css/common_i.css?2014062600" | |
css = css + "\n" + sub_mech.page.body | |
sub_mech.get "https://bk02.jibunbank.co.jp/ibretail/smartphone/css/1000_i.css?2014070604" | |
css = css + "\n" + sub_mech.page.body | |
css = "<style>" + css + "</style>" | |
sub_mech.get "https://bk02.jibunbank.co.jp/ibretail/smartphone/images/logo.png?2014070605" | |
img = sub_mech.page.body | |
base64_str = "data:#{sub_mech.page['content-type']};base64,#{Base64.encode64(img)}" | |
open("top_page.html", "w"){|f| f.puts '<head><META http-equiv="Content-Type" content="text/html; charset=UTF-8"></head>' + top_page.search("body").first.to_html.toutf8.gsub("<h1>", "<h1><img src='#{base64_str}'>") + css.toutf8 } | |
open("meisai_page.html", "w"){|f| f.puts '<head><META http-equiv="Content-Type" content="text/html; charset=UTF-8"></head>' + meisai_page.search("body").first.to_html.toutf8.gsub("<h1>", "<h1><img src='#{base64_str}'>") + css.toutf8} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment