Skip to content

Instantly share code, notes, and snippets.

@phromo
Created January 26, 2012 20:37
Show Gist options
  • Save phromo/1684952 to your computer and use it in GitHub Desktop.
Save phromo/1684952 to your computer and use it in GitHub Desktop.
scraping tekniska verken
require 'rubygems'
require 'celerity'
@browser = browser = Celerity::Browser.new(:resynchronize => true, :log_level => :info)
start_url = "http://www.tekniskaverken.se/mp/tvab/login.xml"
page = @browser.goto(start_url)
username = "<username>"
password = "<password>"
browser.text_field(:name => "handle").value = username
browser.text_field(:name => "password").value = password
browser.select_list(:name => "company").select("Tekniska Verken")
browser.button(:name => "logon").click
browser.link(:url => /forbrukning/).click
browser.link(:url => /matarstallningar/).click
measures = []
measures.push(browser.tables.first.to_a[1..-1])
# Iterate over all pages
page_num = 2
next_page = browser.link(:text => "%s" % page_num)
while next_page.exists? do
next_page.click
measures.push(browser.tables.first.to_a[1..-1])
page_num += 1
next_page = browser.link(:text => "%s" % page_num)
end
pp measures
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment