DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Uri Reader

09.07.2006
| 2004 views |
  • submit to reddit
        // reads and extracts regexp using open-uri

require "open-uri"; include OpenURI
alpha=('a'..'z').to_a

snames=File.new('stations.txt','w')
alpha.each {|a|
open("http://www.irishrail.ie/your_journey/stationpicker.asp?id=#{a}&box=From") {|f|
    f.each_line {|line| snames.puts line}
}}

snames=File.new('stations.txt','r')
data=snames.read
rx1=/sendValue\('([a-zA-Z]+)/
sarr=data.scan(rx1)
stations=sarr.collect{|s| s[0]}
stations.uniq!
puts stations