浏览 1766 次
锁定老帖子 主题:对于RailsCasts的异想天开
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
|
|
---|---|
作者 | 正文 |
发表时间:2009-12-23
最后修改:2010-01-08
主要是熟悉下nokogiri这个包 ##################################################### # Download RailsCasts Tool by jenas # ##################################################### require 'rubygems' require 'open-uri' require 'nokogiri' time = Time.now threads = [] urls = [] exports = "http://feeds.feedburner.com/railscasts" filepath = "C:\\tmp\\" #本地文件保存地址 data = open(exports){|f|f.read} @xml_doc = Nokogiri::XML(data) @xml_doc.css("enclosure").each do |item| urls << item[:url] end for tmp in urls threads << Thread.new(tmp.to_s.split("/")[4]) do |thread| begin output = open(filepath+"#{thread}.mov","wb") open(tmp.to_s) do |f| output.write(f.read) puts f.read.to_s.length end print thread, "-completed" rescue print "Error! with-" , thread end end end threads.each {|thr| thr.join} puts " 下载完成,共耗时:#{Time.now - time}秒" 如果机器上面有wget,可以用以下代码来替换。 imgurls.each do |url| exec = <<EndString cd #{filepath} wget -b -q #{url} EndString system exec end 声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
推荐链接
|
|
返回顶楼 | |