standin000
2013-12-22 11:27:47 +08:00
var $ = require('jquery');
var fs = require('fs');
var request = require('request');
var download = function(uri, filename){
request.head(uri, function(err, res, body){
request(uri).pipe(fs.createWriteStream(filename));
});
};
fs.readFile('./1.html',function(err,data){
if(err) throw err;
HTML = data.toString();
var new_html = $(HTML);
var oldsrc,src;
new_html.find('img').each(function(index,image){
oldsrc = $(image).attr('src');
src = oldsrc.replace(/^.*\//, './');
download(oldsrc, src);
$(image).attr('src', src);
});
console.log(new_html[0].innerHTML);
});
没有找到,自己搞定!