secret
Created

fp more pronporn scrapper

  • Download Gist
1.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
#!/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
end
 
# 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 = links.map { |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
end
end
end

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.