Last active
December 21, 2015 05:49
-
-
Save ryotarai/6259808 to your computer and use it in GitHub Desktop.
UFJ account reporter
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
KEIYAKU_NO = '' | |
PASSWORD = '' | |
MAIL_TO = '' | |
MAIL_FROM = '' # Your Name <your.name@gmail.com> | |
GMAIL_USER = '' | |
GMAIL_PASS = '' | |
ACCOUNT = '' # 口座名や口座番号 |
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
source 'https://rubygems.org' | |
gem 'selenium-webdriver' | |
gem 'mail' |
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_relative './config' | |
require 'selenium-webdriver' | |
require 'net/smtp' | |
require 'mail' | |
driver = Selenium::WebDriver.for :firefox | |
page_source = nil | |
begin | |
driver.navigate.to 'https://entry11.bk.mufg.jp/ibg/dfw/APLIN/loginib/login?_TRANID=AA000_001' | |
driver.find_element(:name, 'KEIYAKU_NO').send_keys(KEIYAKU_NO) | |
driver.find_element(:name, 'PASSWORD').send_keys(PASSWORD) | |
driver.find_element(:css, 'img[alt="ログイン"]').click | |
driver.find_element(:css, 'img[alt="口座一覧(残高)をみる"]').click | |
trs = driver.find_element(:css, 'table.yen_kouza_002').find_elements(:css, 'tr') | |
tr = trs.find{|tr| tr.text.include?(ACCOUNT)} | |
tr.find_element(:css, 'img[alt="明細"]').click | |
page_source = driver.page_source | |
ensure | |
driver.quit | |
end | |
mail = Mail.new do | |
to MAIL_TO | |
from MAIL_FROM | |
subject "Account Report (#{Time.now.to_s})" | |
end | |
html_part = Mail::Part.new do | |
content_type 'text/html; charset=UTF-8' | |
body page_source | |
end | |
mail.html_part = html_part | |
smtp = Net::SMTP.new("smtp.gmail.com", 587) | |
smtp.enable_starttls | |
smtp.start("smtp.gmail.com", GMAIL_USER, GMAIL_PASS, :login) do | |
smtp.send_message(mail.encoded, mail.from, mail.to) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment