Create a gist now

Instantly share code, notes, and snippets.

@gabrielecirulli /1.rb Secret
Created May 20, 2012

What would you like to do?
fp more pronporn scrapper
#!/usr/bin/env ruby
require 'nokogiri'
require 'open-uri'
require 'net/http'
require 'uri'
require 'fileutils'
require 'colorize'
def file_name path
path.split( File::SEPARATOR ).last
# Make results dir
dir = File.join Dir.pwd, "results"
FileUtils.mkdir_p dir
# Request URL
puts "Page URL:"
page = Nokogiri::HTML open gets.chomp
links = page.css( "img" ).map { |img| img['src'] }
hosts = { |x| URI x }.group_by &:hostname
hosts.each do |hostname, uris|
http = Net::HTTP.start hostname
uris.each do |uri|
resp = http.get uri.path
puts "Downloading '#{file_name uri.path}'"
name = file_name uri.path
file_path = File.join dir, name
open file_path, "wb" do |file|
file.write resp.body
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment