Skip to content

Instantly share code, notes, and snippets.

@takuya
Created November 17, 2013 19:23
Show Gist options
  • Save takuya/7517092 to your computer and use it in GitHub Desktop.
Save takuya/7517092 to your computer and use it in GitHub Desktop.
ソフトバンクの請求書を取得 ref: http://qiita.com/takuya_1st/items/baea25d8585d53fddc4a
#!/usr/bin/env ruby
#coding: utf-8
require 'rubygems' if RUBY_VERSION.to_f < 1.9
require 'pp'
module BillScraper
class MySoftbank
attr_accessor :m
def initialize( id=nil, password=nil )
require 'mechanize'
@m = Mechanize.new
@@id = id
@@password = password
end
def go_to_top
m.get "https://my.softbank.jp/msb/d/top"
end
def login(id=nil,password=nil)
id ||= @@id
password ||= @@password
m.get 'https://my.softbank.jp/msb/d/top'
m.submit m.page.forms[0], m.page.forms[0].buttons[0]
m.page.forms[0].fields[0].value= id
m.page.forms[0].fields[1].value= password
m.page.forms[0].submit
end
def latest_meisai
@m.page.links_with( :text=>"ご請求書(内訳)の確認").first.click
#リダイレクト・クッションページ
@m.page.forms[0].submit
#請求内訳
year_month = @m.page.search('form p.current span').text.strip #取得可能な請求書
#一括請求
button = @m.page.forms[0].buttons_with( :name=> "doPrintSbmAll").first
form = @m.page.forms[0]
@m.submit form, button
return { "file_name"=>"ソフトバンク請求書-#{year_month}.pdf", "body"=>m.page.body}
end
def latest_meisai_for_this_number
@m.page.links_with( :text=>"ご請求書(内訳)の確認").first.click
#リダイレクト・クッションページ
@m.page.forms[0].submit
#請求内訳
year_month = @m.page.search('form p.current span').text.strip #取得可能な請求書
#一括請求
#button = @m.page.forms[0].buttons_with( :name=> "doPrintMsn").first #電話番号
button = @m.page.forms[0].buttons_with( :name=> "doPrintSbmAll").first
form = @m.page.forms[0]
@m.submit form, button
return { "file_name"=>"ソフトバンク請求書-#{year_month}.pdf", "body"=>m.page.body}
end
end
end
if $0 == __FILE__ then
# my_soft_bank = BillScraper::MySoftbank.new "0809999999","password"
# my_soft_bank.login
# ret = my_soft_bank.latest_meisai_for_this_number
# open(ret["file_name"], "w"){|f| f.print ret["body"] }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment