-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.js
executable file
·77 lines (63 loc) · 1.34 KB
/
run.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// #!/usr/bin/env casperjs
// @todo
// - 这个文件就不要动了,自动读取suites中的内容,然后执行抓取
// - 加入支持suites=dfh,4399 的输入
/**
* 可以方便的控制只走哪一步,
*/
var require = patchRequire(require);
var fs = require('fs');
var Spider = require('./spider/spider');
var grabInfo = require('suites/info');
var grabFlash = require('suites/flash');
var grabFlash2 = require('suites/flash2');
var test = require('suites/test');
var dfh = require('suites/dfh');
var spider;
function prepare(){
var errFile = 'error.txt';
if (fs.isFile(errFile)) {
fs.remove(errFile);
}
}
// obj是一个
function startGrab(obj ,then){
var options = Spider.utils.extend( (obj.options || {}), {
onFinished: then
});
spider.grab(obj.url, obj.waitSelector, obj.inspect, options);
}
function runSequence(grabs){
var grabObj,
runOne = function () {
// 逻辑
if (grabObj = grabs.shift()) {
var check = grabObj.check;
startGrab(grabObj.prepare(), function () {
check && check();
runOne();
});
} else {
console.log('All done');
spider.exit();
}
};
runOne();
}
/**
* Main Logic
*/
function init() {
spider = Spider.create();
// 清空error.fs._toUnixTimestamp(time);
prepare();
//
runSequence([
grabInfo,
grabFlash,
// grabFlash2,
// test,
// dfh
]);
}
init();