Last active
December 15, 2015 16:49
-
-
Save ryz310/5292103 to your computer and use it in GitHub Desktop.
MySoftbankの料金案内から過去6ヶ月分の請求額取得するプログラムです。
idとpassに電話番号とMySoftbankのパスワード入れると動きます。
mechanize面白いですね^^
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
# -*- coding: utf-8 -*- | |
require 'rubygems' | |
require 'mechanize' | |
require 'openssl' | |
OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE | |
id = '09012345678' | |
pass = '********' | |
top_page = 'https://my.softbank.jp/msb/d/top' | |
m = Mechanize.new | |
# toppage => login | |
m.get(top_page) | |
m.page.forms[0]['msn' ] = id | |
m.page.forms[0]['password'] = pass | |
m.page.forms[0].submit | |
# my softbank | |
m.page.links_with(:text => /請求書/).first.click | |
m.page.forms[0].submit | |
# 6ヶ月分 | |
6.times { |month| | |
# 対象月を表示 | |
print m.page.search('p.current>span').first.content.strip + ' ' | |
m.page.search('div.bill-outline>div.flt_r>table.contract-info tr').find{ |tr| | |
# 請求額を含む行を検索 | |
tr.children.find { |th| | |
th.name == 'th'&& th.content =~ /請求額/ | |
} | |
}.children.each { |td| | |
# 請求額を表示 | |
puts td.content.strip if td.name == 'td' | |
} | |
# 前月分を取得 | |
m.get(m.page.search('p.prev a').first['href']) unless month == 6 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment