Skip to content

Instantly share code, notes, and snippets.

@lcguida
Last active August 29, 2015 14:22
Show Gist options
  • Save lcguida/cb791613e3ae2df654ae to your computer and use it in GitHub Desktop.
Save lcguida/cb791613e3ae2df654ae to your computer and use it in GitHub Desktop.
Universities Worldwide to YAML (Converts all information from http://univ.cc to a YAML file)
require 'open-uri'
require 'nokogiri'
require 'yaml'
start = 1
INCREMENT = 50
has_more = true
File.open('universities.yml', 'w') do |file|
while has_more do
doc = Nokogiri::HTML(open("http://univ.cc/search.php?dom=world&start=#{start}"))
list = doc.css('.fixedWidth ol li a')
has_more = false unless list.any?
list.each do |item|
university = { name: item.text, url: item.attr('href') }
file.puts university.to_yaml
end
start += INCREMENT
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment