forked from lukaszkujawa/node-web-crawler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
crawler.js
executable file
·43 lines (35 loc) · 1015 Bytes
/
crawler.js
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
var argv = require('optimist').argv,
fs = require('fs'),
agent = require('./webcrawler/agent'),
Config = require( './webcrawler/config' );
console.log( '' );
if( argv._[0] === undefined ) {
console.log( 'Usage: node crawler.js [config.json]' );
console.log( '' );
console.log( 'Example: node crawler.js conf.example.json' );
console.log( '' );
process.exit(1);
}
var file = __dirname + '/' + argv._[0];
fs.readFile(file, 'utf8', function (err, data) {
if (err) {
console.log( 'Unable to load "%s"', file );
console.log( '' );
console.log( 'Error message:' );
console.log( err );
console.log( '' );
process.exit(1);
}
try {
data = JSON.parse(data);
}
catch( e ) {
console.log( 'Unable to parse config file "%s"', file );
console.log( '' );
console.log( 'Error message:' );
console.log( e );
console.log( '' );
process.exit(1);
}
agent.initFromConfig( new Config( data ) );
});