使用nodejs写的小爬虫,测试速度,感觉挺快的

//从zngirls的网站上爬取一张图片,并进行异步存储
//http://t1.zngirls.com/gallery/18071/18812/047.jpg (Paste Shift+Insert)
//测试结果异步下载的效率还是相当不错的,感觉比scrapy不差

//jquery使用$符号来进行包封
//var $ = require('jQuery');
//var jsdom = require('jsdom');
//var window = json.json().defaultView;

//var $ = require("jquery")(jsdom.jsdom().createWindow());
var url = require('url');
var http = require('http');
var util = require('util');
var fs = require('fs');
var events = require('events');
var EventEmitter = events.EventEmitter;

var host = 'proxy3.bj.petrochina';
var port = 8080;

function ZngrilDownloader(id, gallery){
    //调用基类构造函数
    //EventEmitter(this);

    //任务ID
    this.id = id;
    //影集索引
    this.gallery = gallery;
}

/*
 ZngrilDownloader.prototype.start = function(){
 //读取页面数目
 var options = {
 host:host,
 port:port,
 path:`http://www.zngirls.com/g/${this.gallery}/`,
 headers:{Referer:'http://www.sina.com',},
 };

 http.get(options, function (res){
 //记录所有的数据
 var html = '';

 res.on('data', function(data){
 html += data;
 });

 res.on('end', function(){
 //使用jquery来进行解析
 text = $(html).find('#dinfo > span').text();
 console.log(text);
 });
 });
 }
 */

ZngrilDownloader.prototype.do = function(count){
    //根据下载的总数来进行循环下载
    for(var i=0; i

你可能感兴趣的:(nodejs)