Skip to content

Instantly share code, notes, and snippets.

@serialhex
Created June 26, 2011 06:04
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 serialhex/1047294 to your computer and use it in GitHub Desktop.
Save serialhex/1047294 to your computer and use it in GitHub Desktop.
awsum downloader of awsumness
#!/usr/bin/env ruby
require 'nokogiri'
require 'open-uri'
require 'pry'
# gets webpages of links and such
puts "getting the main pages..."
docs = [] # i hate doing that
(1..6).each do |n|
page = "http://sumwebsite.com/thing/stuff/moar/#{n}/"
puts "-- getting page: #{page}"
docs << Nokogiri::HTML(open(page))
end
# gets the objects 'm interested in'
puts "selecting stuff from the pages..."
stuff = [] # to keep this beotch in skope
docs.each do |doc|
doc.search('div').each do |div|
next unless (div['class'] == "product_grid_display")
div.search('a').each do |a_tag|
next unless (stuff << a_tag['href'])
end
end
end
# moar blokz!!
puts "getting the images..."
stuff.each do |page|
puts "-- retreving from page: #{page}"
file = '' # makin things sure to stay in skope
title = ''
doc = Nokogiri::HTML(open(page)) # the previous one isn't in skope n e moar!!
doc.search('div').each do |div|
next unless (div['class'] == "imagecol")
obj = div.css('img') # searches fo krap
title = obj[0].attributes['title'].text + ".jpg" # huzzah for chaining methods!!!
img = obj[0].attributes['src'].value
open(img) do |info|
File.open(title, "w") do |file|
puts "-- saving: #{title}"
file.write info.read
end
end
# yeah, so far thi isn't very DRY at all.. in fact it's fucking WET!!!
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment