-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
40 lines (35 loc) · 1023 Bytes
/
Copy pathindex.js
File metadata and controls
40 lines (35 loc) · 1023 Bytes
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
var supercrawler = require("supercrawler"),
crawled = [],
_ = require('lodash'),
argv = require('yargs').argv,
crawler = new supercrawler.Crawler({
// Tme (ms) between requests
interval: 1000,
// Maximum number of requests at any one time.
concurrentRequestsLimit: 5,
// Time (ms) to cache the results of robots.txt queries.
robotsCacheTime: 3600000,
// Query string to use during the crawl.
userAgent: "Mozilla/5.0 (compatible; supercrawler/1.0; +https://github.com/brendonboshell/supercrawler)"
}),
matchExpr = "^" + argv.url.replace(/\//g, '\\/');
crawler.addHandler("text/html", supercrawler.handlers.htmlLinkParser({
urlFilter: function (x) {
if (!x.match(matchExpr)) {
if (!_.includes(crawled, x)) {
console.log(x);
crawled.push(x);
}
return false;
}
return true;
}
}));
crawler.on("crawlurl", function (url) {
console.log(url);
});
crawler.getUrlList()
.insertIfNotExists(new supercrawler.Url(argv.url))
.then(function () {
return crawler.start();
});