webtoon_crawler.js
2.03 KB
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
77
78
79
80
81
82
try {
var Spooky = require('spooky');
} catch (e) {
var Spooky = require('../lib/spooky');
}
function crawler() {
this.webtoonList = new Array();
this.run = run;
}
function getEpisodeList(webtoonNum) {
//spooky를 만든다
var spooky = new Spooky({
child: {
transport: 'http'
},
casper: {
logLevel: 'debug',
verbose: true
}
}, function (err) {
if (err) {
e = new Error('Failed to initialize SpookyJS');
e.details = err;
throw e;
}
spooky.start("http://comic.naver.com/webtoon/list.nhn?titleId=650305");
spooky.then(function () {
var content = function() {
var contentsList = new Array();
var titleList = new Array();
var list = document.querySelectorAll('#content > table > tbody > tr');
for (i = 0; i < list.length; i++) {
tmp = list[i].querySelectorAll('td.title');
for(j=0;j<tmp.length;j++){
titleList.push(tmp[j].innerText);
}
//contentsList.push(list[i].querySelectorAll('td').innerText)
}
return titleList;
}
this.emit('list',this.evaluate(content));
//#content > table > tbody
});
spooky.run();
});
spooky.on('title',function (title) {
console.log('TITLE : ' + title);
})
spooky.on('list',function (titleList) {
for(i=0;i<titleList.length;i++){
console.log('-'+titleList[i]);
}
webtoonList.length=0;
webtoonList=titleList;
})
spooky.on('console', function (line) {
console.log(line);
});
spooky.on('error', function (e, stack) {
console.error(e);
if (stack) {
console.log(stack);
}
});
}
function run() {
//getEpisodeList();
setTimeout(getEpisodeList,5000);
}
module.exports = crawler;