Created
February 24, 2012 17:08
-
-
Save ryantss/1902081 to your computer and use it in GitHub Desktop.
Ruby script to download Natas Travel Fair's brochures.
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
# gem install nokogiri --no-ri --no-doc | |
# gem install open-uri --no-ri --no-doc | |
# | |
# To run just 'ruby download_natas_brochures.rb' | |
# | |
require 'rubygems' | |
require 'nokogiri' | |
require "open-uri" | |
doc = File.open("natas.htm") { |f| Nokogiri::HTML(f) } | |
path = "/tmp/" | |
list = doc.css("div.brcs a") | |
list.each do |e| | |
next unless e['title'] | |
title = e['title'].gsub(/[^0-9a-z]+/i, '_') | |
url = e['href'] | |
filename = path + title + '_' +url.split('/').last | |
puts "#{title}: #{url} - #{filename}" | |
next if File.exist? filename or url == 'http://sg.tripzilla.com/files/66899.pdf' | |
open(url) { |f| File.open(filename, 'wb') { |file| file.puts(f.read) } } | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment