Created
January 26, 2012 20:37
-
-
Save phromo/1684952 to your computer and use it in GitHub Desktop.
scraping tekniska verken
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
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