Created
November 17, 2012 08:02
-
-
Save yyyyyyuanfei/4094147 to your computer and use it in GitHub Desktop.
Download PDF files from a WebPage
This file contains hidden or 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
| require 'nokogiri' | |
| require 'open-uri' | |
| require 'cocaine' | |
| task :default do | |
| pattern = ':url' | |
| line = Cocaine::CommandLine.new('wget', pattern) | |
| base_url = 'http://www.cs.sjtu.edu.cn/~jdyu/teaching/SE/fall2012/' | |
| file = 'index.html' | |
| document = Nokogiri::HTML(open(base_url + file)) | |
| document.css('a').each do |link| | |
| file = link['href'] | |
| next unless file.end_with?('.pdf') | |
| line.run(:url => base_url + file) | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
USAGE