Created
February 27, 2014 19:12
-
-
Save GSI/9256980 to your computer and use it in GitHub Desktop.
Capybara-Script for scraping current financial balance at UTE (Uruguay's power company)
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
#!/usr/bin/env ruby | |
require 'capybara' | |
user_id = ARGV.shift || 'YOUR_USERID' | |
password = ARGV.shift || 'YOUR_PASSWORD' | |
Capybara.run_server = false | |
Capybara.current_driver = :selenium | |
Capybara.app_host = 'https://autoservicio.ute.com.uy' | |
module Checks | |
class Ute | |
include Capybara::DSL | |
def log_in(user_id, password) | |
visit '/SelfService/SSvcController/login' | |
fill_in 'userId', with: user_id | |
fill_in 'password', with: password | |
click_button 'Entrar' | |
end | |
def check_balance | |
balance_label_text = 'Deuda Total:' | |
within(:css, '#Content') do | |
balance = find(:xpath, "//tr[td[@class='label']='#{balance_label_text}'][1]/td/following-sibling::td[1]") | |
balance.text.delete!('$ ') | |
end | |
end | |
end | |
end | |
ute = Checks::Ute.new | |
ute.log_in(user_id, password) | |
p ute.check_balance |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment