随便写写 呵呵
主要是熟悉下nokogiri这个包
如果机器上面有wget,可以用以下代码来替换。
主要是熟悉下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