Skip to content

Instantly share code, notes, and snippets.

@jaen
Created February 24, 2013 18:36
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 jaen/5024965 to your computer and use it in GitHub Desktop.
Save jaen/5024965 to your computer and use it in GitHub Desktop.
Awfully dumb ruby 4chan downloader. Does the job though.
#!/usr/bin/env ruby
require 'rubygems'
require 'mechanize'
BASE_PAGE_URL = ARGV[0]
LAST_PART_REGEXP = /\/([^\/]+)$/
BASE_DIR = LAST_PART_REGEXP.match(BASE_PAGE_URL)[1]
`mkdir #{BASE_DIR}`
agent = Mechanize.new
page = agent.get BASE_PAGE_URL
page.links.select { |link| (link.dom_class || "").index "fileThumb" }.each do |image_link|
image_filename = LAST_PART_REGEXP.match(image_link.href)[1]
puts "Saving #{image_filename}..."
`wget -nc -P #{BASE_DIR} -nd http:#{image_link.href}`
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment