-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy path03_galleryListGrep.js
76 lines (66 loc) · 2.28 KB
/
03_galleryListGrep.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
/**
* Created by ecst_000 on 2016-01-09.
*/
var async = require('async');
var cheerio = require('cheerio');
var config = require('./core/config');
var fs = require('fs');
var articles = [];
async.waterfall([
// get auth
function (callback) {
console.log('get auth');
require('./core/auth')(config.userId, config.password, config.rsaPublic, config.rsaModulus,
callback);
},
// paring cookie
function (cookies, callback) {
console.log('paring cookies');
var cookieLength = cookies.length;
var newCookie = [];
for (var i = 0; i < cookieLength; i++) {
var chuck = cookies[i];
newCookie.push(chuck.substring(0, chuck.indexOf('; ')));
}
callback(null, newCookie.join('; '));
},
function (cookies, callback) {
require('./core/galleryList')(cookies, config.clubId, 1, callback);
},
function (cookies, data, callback) {
console.log('parsing first page');
require('./core/parseGalleryList')(cookies, data, callback);
},
function (cookies, result, callback) {
console.log('get page count');
fs.writeFile('result/gallery_list_1.txt', JSON.stringify(result.articles));
var queue = [];
for (var i = 2; i <= result.maxPage; i++) {
queue.push(i);
}
callback(null, cookies, queue);
},
function (cookies, queue) {
async.eachSeries(
queue,
function (pageNo, next) {
async.waterfall([
function (subroutine) {
require('./core/galleryList')(cookies, config.clubId, pageNo, subroutine);
},
function (cookies, data, subroutine) {
console.log('parsing page - ' + pageNo);
require('./core/parseGalleryList')(cookies, data, subroutine);
},
function (cookies, result) {
fs.writeFile('result/gallery_list_' + pageNo + '.txt', JSON.stringify(result.articles));
setTimeout(next, 2000);
}
]);
},
function () {
console.log('galleries done');
}
);
}
]);