Created
March 2, 2013 11:07
-
-
Save zudochkin/5070537 to your computer and use it in GitHub Desktop.
images downloader from http://xxxpanther.tumblr.com/
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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