Skip to content

Instantly share code, notes, and snippets.

@zudochkin
Created March 2, 2013 11:07
Show Gist options
  • Save zudochkin/5070537 to your computer and use it in GitHub Desktop.
Save zudochkin/5070537 to your computer and use it in GitHub Desktop.
images downloader from http://xxxpanther.tumblr.com/
require 'nokogiri'
require 'open-uri'
require 'pathname'
class Downloader
def initialize(url='xxxpanther.tumblr.com')
@url = url
end
def get_images_from_url(page=1)
Nokogiri::HTML(open("http://#{ @url }/page/#{ page }")).css('img.shakeimage').map{ |img| img[:src] }
end
def process
Dir.mkdir('./babes') unless Dir.exists? './babes'
page = 0
until (images = get_images_from_url(page += 1)).empty?
print "Images on #{ page } page: "
images.each { |image| download_image(image) }
puts
end
end
def download_image(url)
open(url) do |f|
File.open("./babes/#{ Pathname.new(url).basename.to_s }", 'wb') do |file|
file.puts f.read
end
end
print '.'
end
end
Downloader.new.process
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment