var m = match[i].match(reg2);
if (m && m[2]) {
var url = m[2];
let imgUrl = r_url.resolve(URL, url);
if (!isDownMap[imgUrl]) {
var uo = r_url.parse(imgUrl);
let filepath = CWD + '/' + uo.hostname + uo.pathname;
makedir(path.dirname(filepath), function () {
http.get(imgUrl, function (res) {
res.pipe(fs.createWriteStream(filepath));
})
})
isDownMap[imgUrl] = 1;
}
}
}
});
});
}
var URLS = process.argv[2].split(',');
var CWD = process.cwd();
//下载资源
URLS.forEach(function (URL) {
var uo = r_url.parse(URL);
var filepath;
if (uo.pathname == '/' || uo.pathname == '') {
filepath = CWD + '/' + uo.hostname + '/index.html';
} else {
filepath = CWD + '/' + uo.hostname + uo.pathname;
}
makedir(path.dirname(filepath), function () {
http.get(URL, function (res) {
if (URL.indexOf('.css') != -1 || (res.headers["content-type"] && res.headers["content-type"].indexOf('text/css')!= -1)) {
console.log('down images form css file:' + URL + '.');
downImgFromCss(URL);
}
res.pipe(fs.createWriteStream(filepath));
})
});
});
down.js downHtml.js 放在同一个文件夹下 通过下列 cmd 运行
D:phantomjs-2.0.0-windowsbinphantomjs.exe down.js http://www.youku.com/
以上所述就是本文的全部内容了,希望大家能够喜欢。









