Crawler 模块
安装
npm i crawler
示例
var Crawler = require("crawler");
var c = new Crawler({
maxConnections : 10,
callback : function (error, res, done) {
if(error){
console.log(error);
}else{
var $ = res.$;
console.log($("title").text());
}
done();
}
});
c.queue('http://www.amazon.com');
c.queue(['http://www.google.com/','http://www.yahoo.com']);
c.queue([{
uri: 'http://parishackers.org/',
jQuery: false,
callback: function (error, res, done) {
if(error){
console.log(error);
}else{
console.log('Grabbed', res.body.length, 'bytes');
}
done();
}
}]);
c.queue([{
html: '<p>This is a <strong>test</strong></p>'
}]);
方法