Skip to content

Instantly share code, notes, and snippets.

@sebastiangeiger
Created May 7, 2011 12:00
Show Gist options
  • Save sebastiangeiger/960445 to your computer and use it in GitHub Desktop.
Save sebastiangeiger/960445 to your computer and use it in GitHub Desktop.
DKB crawler
#!/usr/bin/ruby
require 'rubygems'
require "mechanize"
require 'logger'
def crawl_dkb(credentials)
agent = Mechanize.new { |a| a.log = Logger.new("mech.log") }
agent.user_agent_alias = 'Mac Safari'
page = agent.get("https://banking.dkb.de/dkb/-?$javascript=disabled")
login_form = page.form_with(:name => "login")
login_form.field_with(:name => "j_username").value = credentials[:user]
login_form.field_with(:name => "j_password").value = credentials[:password]
login_results = agent.submit(login_form)
balances = login_results.parser.xpath("//table[@class='maintable']//table[@class='searchResultTable']//span").collect{|e| my_to_int(e.text)}
login_results.link_with(:text => "Abmelden").click #Abmelden = german for logoff
return balances[0..1]
end
if __FILE__ == $PROGRAM_NAME
credentials = {}
credentials[:dkb] = {:user => "myusername", :password => "mypassword"}
balances = Array.new
balances += crawl_dkb(credentials[:dkb])
puts balances.inspect
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment