From: Anurag Priyam Date: 2011-02-23T23:46:24+09:00 Subject: Re: How to automate download pdf from web in ruby > e.g : http://www.example.com/abc.pdf > > Now from above URL I just want to automate download "abc.pdf" rather > than > > click on save. > > I am looking for some good solutions and suggestions. On a Linux box you can happily use wget. Here is a simple use, and throw script that I used to download video lectures (of Design of Machine Elements :)) from NPTEL[1]. I hope this gives you an idea. require 'rubygems' require 'nokogiri' require 'open-uri' proxy = ENV["http_proxy"] page = "http://nptel.iitm.ac.in/video.php?courseId=1063" # get the title of all the lectures to use as a filename later doc = Nokogiri open(page, :proxy => proxy) titles = doc.search("td.videolink a").map(&:text) # download url follows a common pattern # construct the url, and download it (1..9).each do |i| url = "http://npteldownloads.iitm.ac.in/flv/1063/lec0#{i}.flv" lecture = titles[i - 1] puts lecture %x|wget -c '#{url}' -O '#{lecture}'| end (10..40).each do |i| url = "http://npteldownloads.iitm.ac.in/flv/1063/lec#{i}.flv" lecture = titles[i - 1] puts lecture %x|wget -c '#{url}' -O '#{lecture}'| end [1] http://nptel.iitm.ac.in/ -- Anurag Priyam http://about.me/yeban/