Friday, March 16, 2007

Ruby to screen scrape whether my train home is on time

require 'hpricot'
require ' open-uri'

while(1) do
html = open( 'http://www.livedepartureboards.co.uk/ldb/sumdep.aspx?T=MAN' )
doc = Hpricot(html)
results = doc.search("//td:eq(0)[text()='Middlesbrough']/../td:eq(1)[text()='17:55']/../td:eq(2)/text() ")
results.each { |r| puts "#{Time.new.strftime('%H:%M')} :\t#{r}" }
sleep(60)
end


# ruby is such fun!

No comments: