匹配网站中的脚本<script src="public/ab.js"></script>,
并且按照其中的目录结构下载保存.
并且按照其中的目录结构下载保存.
require 'open-uri'
url = 'http://www.feyasoft.com'
root = '/root/Desktop/fey'
open(url) do |f|
f.each do |l|
if l =~ /<script\stype="text\/javascript"\ssrc="(.+)"><\/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