Skip to content

Instantly share code, notes, and snippets.

@andrew
Created September 9, 2014 07:24
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 andrew/dc576edbb4465f0f9d55 to your computer and use it in GitHub Desktop.
Save andrew/dc576edbb4465f0f9d55 to your computer and use it in GitHub Desktop.
Download the name of every published gem from rubygems.org
require 'rubygems'
require 'nokogiri'
require 'open-uri'
require 'yaml'
@names = []
def download_page(path)
doc = Nokogiri::HTML(open('http://rubygems.org' + path))
doc.css('.gems a').each do |link|
url = link.attributes['href'].to_s
name = url.match(/\/gems\/(.+)/)[1]
puts name
@names << name
end
if doc.css('a[rel=next]').any?
link = doc.css('a[rel=next]').first
path = link.attributes['href'].to_s
download_page path
end
end
('a'..'z').each do |letter|
puts "Downloading '#{letter}'"
download_page("/gems?letter=#{letter}&page=1")
end
File.open('gemnames.yaml', 'w') {|f| f.write(YAML.dump(@names)) }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment