Created
June 26, 2011 06:04
-
-
Save serialhex/1047294 to your computer and use it in GitHub Desktop.
awsum downloader of awsumness
This file contains 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
#!/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