Skip to content

Instantly share code, notes, and snippets.

@rudle
Created June 30, 2011 12:05
Show Gist options
  • Save rudle/1056111 to your computer and use it in GitHub Desktop.
Save rudle/1056111 to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'nokogiri'
require 'httparty'
doc = Nokogiri(HTTParty.get('http://www.gutenberg.org/wiki/Harvard_Classics_(Bookshelf)'))
ids = doc.css('a').select{|a| a.attr('title') =~ /ebook:/ }.map do |a|
a.attr('title') =~ /ebook:(\d+)/
{:title => a.text, :id => $1 }
end.compact.uniq
ids.each do |book|
sleep 2
File.open("/tmp/gutenberg/#{book[:id]}-#{book[:title]}", "w+") do |file|
file << HTTParty.get("http://gutenberg.org/ebooks/#{book[:id]}.kindle.noimages")
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment