Skip to content

Instantly share code, notes, and snippets.

@rxw1
Last active December 28, 2015 09:19
Show Gist options
  • Save rxw1/7477901 to your computer and use it in GitHub Desktop.
Save rxw1/7477901 to your computer and use it in GitHub Desktop.
Download some files from some website… Note: Don't use it. It's a little bit evil.
#!/usr/bin/env ruby
# -*- encoding: utf-8 -*-
#
# Fri Nov 15 03:21:26 CET 2013
#
require 'nokogiri'
require 'open-uri'
require 'fileutils'
doc = Nokogiri::HTML(open("http://domian.alpha-labs.net/archiv/"))
doc.search('//*[@id="post-51"]/div/ul/li/a').each do |a|
Nokogiri::HTML(open(a['href'])).search('//tr')[2..-1].each do |tr|
date = Date.parse(tr.children[0].content)
subject = tr.children[1].content.chomp
url = tr.children[2].children[0]['href']
dir = "#{Dir.pwd}/#{date.strftime('%Y/%m')}/"
Dir.exists?(dir) || FileUtils.mkdir_p(dir)
file = "#{date.strftime('%Y-%m-%d')}_#{subject.downcase.gsub(" ", "_")}.#{url.split(".").last}"
puts dir + file
File.open(dir + file, "wb") do |file|
file.write open(url).read
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment