Skip to content

Instantly share code, notes, and snippets.

@jsvd
Created December 26, 2009 17:10
Show Gist options
  • Save jsvd/263987 to your computer and use it in GitHub Desktop.
Save jsvd/263987 to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'mechanize'
require 'highline'
agent = WWW::Mechanize.new
highline = HighLine.new
main_page = agent.get('https://m.caixadirecta.cgd.pt')
page2 = main_page.form_with(:name => 'Login_execute') do |form|
form["requestedCredentials.USER_NAME.value"] = highline.ask("Enter your username: " ) { |q| q.echo = "x"}
form["requestedCredentials.ACCESS_CODE.value"] = highline.ask("Enter your password: " ) { |q| q.echo = "x"}
end.click_button
page2 = agent.get('https://m.caixadirecta.cgd.pt/pocketBank/PosicaoGlobal.action')
puts page2.links[1].text
agent.get('https://m.caixadirecta.cgd.pt/pocketBank/Logout.action')
require 'rubygems'
require 'mechanize'
require 'highline'
agent = WWW::Mechanize.new #TODO certificate handling
highline = HighLine.new
login_page = agent.get('https://m.caixadirecta.cgd.pt')
main_page = login_page.form_with(:name => 'Login_execute') do |form|
form["requestedCredentials.USER_NAME.value"] = highline.ask("Enter your user: " ) { |q| q.echo = "x"}
form["requestedCredentials.ACCESS_CODE.value"] = highline.ask("Enter your password: " ) { |q| q.echo = "x"}
end.click_button
page2 = agent.get('https://m.caixadirecta.cgd.pt/pocketBank/PosicaoGlobal.action')
puts "Total: "
puts page2.links[1].text
# link "Movimentos"
movimentos = agent.click(page2.links[3])
puts ["Data".center(8),"Descrição".center(24), "Montante".center(10)].join("|")
# format html doc to a table
movimentos.parser.xpath('//table//tr')[4..-1].each do |row|
cells = row.xpath('td')
next unless cells.size > 3
print cells[0].text.strip.center(7)
print " | "
print cells[2].text.strip.rjust(22)
print " | "
print cells[4].text.strip.rjust(10)
print " | "
puts ""
end
agent.get('https://m.caixadirecta.cgd.pt/pocketBank/Logout.action')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment