nodeJs抓取网页
var fs = require('fs'); var jquery = require('jquery'); var url = require('url'); var data = { 0 : 'http://www.baidu.com/s?wd=nodeJS%20doc&pn=', 1 : '&tn=myie2&ie=utf-8&ch=3' //baidu_search_on_page1 }; var page = 10; do{ page--; jquery.get(data[0]+page+data[1],function(html){ (function(){ success(html,page) })(); }); }while(page); function bind(fn,context){ return function(){ fn.call(context) }; }; function success(html,page){ //fs.appendFile() //console.log(html,page) fs.appendFile(page+'.html',html,function(err){ if(err)throw err; console.log('done') }) }
天道酬勤