forked from pei-jung/spider
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
52 lines (43 loc) · 1.14 KB
/
main.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
44
45
46
47
48
49
50
51
52
#!/usr/bin/env casperjs
var conf = require('config.json');
conf.casper.viewportSize = conf.viewport[0];
var casper = require('casper').create(conf.casper);
var colorizer = require('colorizer').create('Colorizer');
var fs = require('fs');
var ImageComparator = require('modules/image-comparator').ImageComparator;
var Login = require('modules/login').Login;
var Spider = require('modules/spider').Spider;
var TreeModel = require('tree-model');
var utils = require('utils');
var x = require('casper').selectXPath;
var loginInstance = new Login();
var tree = new TreeModel();
var spiderInstance = new Spider(conf.homepage.url);
var styleType = {
'error': 'red',
'pass': 'green',
'status': 'magenta',
'info': 'cyan',
'warning': 'yellow'
};
function styleMsg(msg, type) {
var tag = colorizer.format('[' + type.toUpperCase() + ']', {
bg: 'black',
fg: styleType[type],
bold: true
});
return tag + ' ' + msg;
};
casper.start(
conf.homepage.url,
function() {
console.log(styleMsg('Liferay web crawler is running...', 'status'));
spiderInstance.crawl();
}
);
casper.run(
function() {
casper.echo('Crawling complete.');
casper.exit();
}
);