LoginSignup
8
9

More than 5 years have passed since last update.

ソフトバンクの請求書を取得

Posted at
softbank.rb
#!/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"] }

エントリはこっち。

8
9
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
9