ruby 杂记

阅读更多
匹配网站中的脚本,
并且按照其中的目录结构下载保存.


require 'open-uri'

url = 'http://www.feyasoft.com'
root = '/root/Desktop/fey'

open(url) do |f|
   f.each do |l|
      if l =~ /<\/script>/
          file_path = $1
          if file_path =~ /\/(\w+\.js)/
            path, file = $`,$1
            fullpath = root + path
            system("mkdir -p #{fullpath}")
            open(url + file_path) do |res|
              File.open(root + file_path, 'w+') do |ff|
                ff.write(res.readlines)
              end
            end
          end
      end
   end
end

你可能感兴趣的:(Ruby,脚本,F#)