Skip to content

Instantly share code, notes, and snippets.

@ryantss
Created February 24, 2012 17:08
Show Gist options
  • Save ryantss/1902081 to your computer and use it in GitHub Desktop.
Save ryantss/1902081 to your computer and use it in GitHub Desktop.
Ruby script to download Natas Travel Fair's brochures.
# 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