Yorusika.js
1.95 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
var request = require('request');
var cheerio = require('cheerio');
function crawl_yorusika(url, callback){
let json_album = [], json_year = [], json_track = [], json_image = [];
let yorusika = [];
var track;
var year;
request(url, function (err, res, body) {
const $ = cheerio.load(body);
var index;
var album_num = 0;
console.log($('.discography_contents').length);
for (var i = $('.discography_contents').length; i >=1; i--) {
year = $('body > article > section > div > div:nth-child('+i+') > div.discography_text > div.discography_date').text();
year = year.substr(0,year.length-7);
json_year.push(year);
if(i == 3){
track = $('body > article > section > div > div:nth-child('+i+') > div.discography_text > div.discography_description').text();
track = track.substr(6);
track = track.substr(0,track.length-22);
}
else{
track = $('body > article > section > div > div:nth-child('+i+') > div.discography_text > div.discography_description').text();
track = track.substr(6);
track = track.substr(0,track.length-7);
}
json_track.push(track);
var check = false
album_num++;
var album_name = '';
album = $('body > article > section > div > div:nth-child('+i+') > div.discography_text > div.discography_title').text();
for(var j = 0; j<album.length;j++){
if(album[j] == '「')
check = true;
if(check == true)
album_name += album[j];
}
album_name = album_num + '. ' + album_name
json_album.push(album_name);
}
yorusika.push({ json_album, json_year, json_track});
callback(yorusika);
});
}
exports.crawl_yorusika = crawl_yorusika;