Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Branch: master
Fetching contributors…

Cannot retrieve contributors at this time

59 lines (48 sloc) 2.093 kB

easyspider

  • NPM version
  • Dependencies Status
  • Build Status
  • NPM Stats
  • NPM Downloads

a mini spider

install:

npm install easyspider

Usage:

    var Spider = require('easyspider');
    var spider = new Spider();

    function get_title(){
        console.log('get_title','start');
        spider.route('http://www.baidu.com',function(error, $){
          assert.equal($('title').text(),'百度一下,你就知道');
          console.log('get_title','[ OK ]');
        });
    }
    function get_json(){
        console.log('get_json','start');
        spider.route('http://login.renren.com/ajax/getEncryptKey',{json:true},function(error, json){
          assert.equal(json.rkey.length,32);
          console.log('get_json','[ OK ]');
        }); 
    }
    function use_outer_cookiejar(){
        console.log('use_outer_cookiejar','start');
        var cookiejar = require('request').jar();
        cookiejar.setCookie('key1=value1','http://www.domain-1.com',noop);
        spider.route('http://www.baidu.com',{cookiejar:cookiejar},function(error, $){
            var cookiestring = spider.getCookiejar().getCookieString('http://www.domain-1.com');
            assert.equal(cookiestring,'key1=value1');
            console.log('use_outer_cookiejar','[ OK ]');
        });
    }
    function use_inner_cookiejar(){
        console.log('use_inner_cookiejar','start');
        var cookiejar = spider.getCookiejar();
        cookiejar.setCookie('key2=value2','http://www.domain-2.com',noop);

        spider.route('http://www.baidu.com',function(error, $){
            var cookiestring = spider.getCookiejar().getCookieString('http://www.domain-2.com');
            assert.equal(cookiestring,'key2=value2');
            console.log('use_inner_cookiejar','[ OK ]');
        }); 
    }


Jump to Line
Something went wrong with that request. Please try again.