Skip to content

Instantly share code, notes, and snippets.

@takuya
Created Jul 5, 2014
Embed
What would you like to do?
#coding:utf-8
# @author https://github.com/takuya
#
# Copyright (C) 2012-2013 takuya. All rights reserved.
#
# This program is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free Software
# Foundation; either version 2 of the License, or (at your option) any later
# version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
# details.
#
# You should have received a copy of the GNU General Public License along with
# this program; if not, write to the Free Software Foundation, Inc., 59 Temple
# Place, Suite 330, Boston, MA 02111-1307 USA
#
module BillScraper
def sasion_card_current_month( login_id , passwd)
require 'mechanize'
m = Mechanize.new
m.get "http://www.saisoncard.co.jp/"
m.page.link_with( :text => /ログイン/).click
raise unless m.page.forms[0]
m.page.forms[0]
m.page.forms[0].field_with( :name => /id/i).value = login_id
m.page.forms[0].field_with( :name => /pass/i).value = passwd
m.page.forms[0].submit
raise unless m.page.link_with( :text => /利用明細/)
m.page.link_with( :text => /利用明細/).click
raise unless m.page.link_with( :text => /web明細ダウンロード/i )
m.page.link_with( :text => /web明細ダウンロード/i ).click
raise unless m.page.header["content-disposition"] =~ /filename=([^\.]+\.pdf)/
f_name = Regexp.last_match[1]
m.page.save f_name
return f_name
end
module_function :sasion_card_current_month
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment