Guckkasten.js
2.36 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
var request = require('request');
var cheerio = require('cheerio');
function crawl_guckkasten(callback){
var n = 0;
var guckkasten = [];
crawl(function(json_album,json_year,json_track){
n++
if (n == 10) {
var j;
var a, y, t;
for (var i = 1; i < json_year.length; i++) {
y = json_year[i];
a = json_album[i];
t = json_track[i]
j = i - 1;
while (j >= 0 && json_year[j] > y) {
json_album[j + 1] = json_album[j];
json_year[j + 1] = json_year[j];
json_track[j + 1] = json_track[j];
j--;
}
json_album[j + 1] = a;
json_year[j + 1] = y;
json_track[j + 1] = t;
}
for(var i = 0; i<json_album.length; i++){
json_album[i] = (i+1)+'. ' +json_album[i];
}
guckkasten.push({json_album, json_year, json_track});
callback(guckkasten);
}
})
}
function crawl(callback){
var url;
let json_album = [], json_year = [], json_track = [];
var track;
var year;
var album;
for (var i = 1; i <= 13; i++) {
url = 'http://www.interparkenter.com/guckkasten/Album/' + i;
if (!(i > 9 && i < 13)) {
request(url, function (err, res, body) {
const $ = cheerio.load(body);
var track_num = 0;
var album_track = '';
$('#divDetail > div.disco_left_box > div.track_area > div > ol').find('li').each(function () {
track_num++;
track = $('#divDetail > div.disco_left_box > div.track_area > div > ol > li:nth-child(' + track_num + ')').text()
album_track += track + '\n';
})
json_track.push(album_track);
year = $('#divDetail > div.disco_right_box > div.Introduction > p.txt_release').text();
year = year.substr(3);
json_year.push(year);
album = $('#divDetail > div.disco_right_box > div.Introduction > p.txt_title').text();
json_album.push(album);
callback(json_album,json_year,json_track);
});
}
}
}
exports.crawl_guckkasten = crawl_guckkasten;