Giter Site home page Giter Site logo

easyspider's Introduction

#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 ]');
		});	
	}


easyspider's People

Contributors

sxyizhiren avatar

Stargazers

 avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.