Skip to content

Instantly share code, notes, and snippets.

@rdougan
Created November 24, 2009 09:03
Show Gist options
  • Save rdougan/241750 to your computer and use it in GitHub Desktop.
Save rdougan/241750 to your computer and use it in GitHub Desktop.
#! /usr/bin/env ruby
require 'rubygems'
require 'mechanize'
# Enter your username and password
login = ''
password = ''
# Enter your sortcode and account number.
# this appears on the first page when you login, it should be a link and should look like this:
# 11-08-99 00601234
sortcode_and_account_number = ''
if login == ""
puts "# Please enter your username"
login = gets.chop
end
if password == ''
puts "# Please enter your password"
password = gets.chop
end
agent = WWW::Mechanize.new
#get the login page
login_page = agent.get('https://www.halifax-online.co.uk/_mem_bin/Formslogin.asp')
#get the question
question = login_page.search('/html/body/div[2]/form/div[3]/div[2]/fieldset[2]/div/div[2]/div[4]/div').first.children.text
# Fill out these questions/answers if you don't want to enter them everytime
# if question == ""
# answer = ""
# elsif question == ""
# answer = ""
# elsif question == ""
# answer = ""
# elsif question == ""
# answer = ""
# else
puts "# " + question
answer = gets.chop
# end
#get the login form
login_form = login_page.form('frmFormsLogin')
login_form.Username = login
login_form.password = password
login_form.answer = answer
#submit the form
account_page = agent.submit(login_form, login_form.buttons.first)
#get the link to the next page (balance)
balance_page = agent.click account_page.link_with(:text => sortcode_and_account_number)
#get the balance from the page
tds = balance_page.search('table.bankingSummaryContainer td.summaryBoxesValues')
current_balance = tds[3].children.text
current_available = tds[5].children.text
puts "##############################################"
puts "# Current balance"
pp current_balance.gsub(/\302\226/, '-').gsub(/\302\243/, '').gsub(' ', '').strip
puts "# Current available balance"
pp current_available.gsub(/\302\243/, '').strip
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment