Skip to content

Instantly share code, notes, and snippets.

@jeffreyiacono
Created February 5, 2010 06:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeffreyiacono/295579 to your computer and use it in GitHub Desktop.
Save jeffreyiacono/295579 to your computer and use it in GitHub Desktop.
#! /usr/bin/ruby
require 'rubygems'
require 'nokogiri'
require 'open-uri'
DIRECTORY_QUERY_URL_FOR = "https://web.middlebury.edu/database/directory/?cn="
"A".upto("Z") do |letter|
url = "#{DIRECTORY_QUERY_URL_FOR}#{letter}"
doc = Nokogiri::HTML(open(url))
doc.css("tr").each do |item|
# initialize
output ||= []
# set
output.push item.css("td:nth-child(1)").text
output.push item.css("td:nth-child(2)").text
output.push item.css("td:nth-child(3)").text
output.push item.css("td:nth-child(4)").text
output.push item.css("td:nth-child(5)").text
# output into in csv format
puts '"' + output.map { |v| v.strip }.join("\",\"") + '"'
# reset
output.clear
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment