前面那篇文章图里的本子的下载代码

2015-4-13 19:48:13

QQ截图20150413194519
nodejs,需要request包。没找到压缩包下载,所以自己写了一个

var fs = require('fs');
var request = require('request');
request.get('http://www.aaadream.com/thread-25468-1-1.html', function (err, res, body){
    var reg = /http\:\/\/ist2\-2\.filesor\.com\/.*\.jpg/ig;
    var result = body.match(reg);
    console.log(result);
    var path = require('path');
    var comp = 0;
    var savepath = path.join(__dirname, 'save');
    if (!fs.existsSync(savepath)){
        fs.mkdirSync(savepath);
    }
    result.forEach(function(e){
        request.get(e, function (){
            comp++;
            console.log(comp + '/' + result.length);
            if (comp == result.length){
                process.exit();
            }
        }).pipe(fs.createWriteStream(path.join(savepath, path.basename(e))));
    });
});