node-crawler 介绍
node-crawler这是一个比较好用的node.js爬虫框架,我们可以使用最亲切的jQuery语法来解析响应返回的页面。
node-crawler安装
npm install crawler
node-crawler使用
var Crawler = require("crawler");
var c = new Crawler({
maxConnections : 10,
// This will be called for each crawled page
callback : function (error,res,done) {
if(error){
console.log(error);
}else{
var $ = res.$;
// $ is Cheerio by default
//a lean implementation of core jQuery designed specifically for the server
console.log($("title").text());
}
done();
}
});
// Queue just one URL,with default callback
c.queue('http://www.amazon.com');
// Queue a list of URLs
c.queue(['http://www.google.com/','http://www.yahoo.com']);
// Queue URLs with custom callbacks & parameters
c.queue([{
uri: 'http://parishackers.org/',
jQuery: false,
// The global callback won't be called
callback: function (error,done) {
if(error){
console.log(error);
}else{
console.log('Grabbed',res.body.length,'bytes');
}
done();
}
}]);
// Queue some html code directly without grabbing (mostly for tests)
c.queue([{
html: '<p>This is a <strong>test</strong></p>'
}]);
GitHub:https://github.com/bda-research/node-crawler
网站描述:一款最好的node.js爬虫工具
node-crawler
小编说
以上是编程之家为你收集整理的node-crawler全部内容。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。