-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcrawler.js
More file actions
47 lines (44 loc) · 1.18 KB
/
crawler.js
File metadata and controls
47 lines (44 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
const Crawler = require("crawler");
let c = new Crawler({
// is the minimum time gap between two tasks. When rateLimit is set to a non-zero value, maxConnections will be forced to 1.
rateLimit: 300,
// Maximum number of tasks that can be running at the same time
maxConnections : 10,
// This will be called for each crawled page
callback : function (error, res, done) {
if(error){
console.log(error);
}else{
let $ = res.$;
// $ is Cheerio by default
//a lean implementation of core jQuery designed specifically for the server
console.log($("title").text());
}
done();
}
});
const baseUrl = 'https://www.qqtn.com'
// queue with Custom callback
c.queue([{
uri: 'https://www.baidu.com',
callback: function (err, res, done) {
if (err) {
console.log(err);
} else {
console.log('Grabbed', res.body.length, 'bytes');
}
done()
}
}])
// queue HTML code directly
c.queue([{
html: '1咯',
callback: function (err, res, done) {
if (err) {
console.log(err);
} else {
console.log('Grabbed', res.body.length, 'bytes');
}
done()
}
}]);