Skip to content

Instantly share code, notes, and snippets.

@yyyyyyuanfei
Created November 17, 2012 08:02
Show Gist options
  • Select an option

  • Save yyyyyyuanfei/4094147 to your computer and use it in GitHub Desktop.

Select an option

Save yyyyyyuanfei/4094147 to your computer and use it in GitHub Desktop.
Download PDF files from a WebPage
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
@yyyyyyuanfei
Copy link
Copy Markdown
Author

USAGE

gem install nokogiri
gem install cocaine
rake -f get_pdf`

@yyyyyyuanfei
Copy link
Copy Markdown
Author

多了个点- -

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment