Showing
3 changed files
with
70 additions
and
9 deletions
... | @@ -4,8 +4,10 @@ var express = require('express'); | ... | @@ -4,8 +4,10 @@ var express = require('express'); |
4 | var http = require('http'); | 4 | var http = require('http'); |
5 | var bodyParser = require('body-parser'); | 5 | var bodyParser = require('body-parser'); |
6 | var app = express(); // express 객체 저장 | 6 | var app = express(); // express 객체 저장 |
7 | -var webcrawl = require('./crawling/Reol'); | ||
8 | var async = require('async'); | 7 | var async = require('async'); |
8 | + | ||
9 | +var crawlReol = require('./crawling/Reol'); | ||
10 | +var crawlYonezu = require('./crawling/Yonezu'); | ||
9 | var singer; | 11 | var singer; |
10 | 12 | ||
11 | //body-parser 미들웨어 사용 | 13 | //body-parser 미들웨어 사용 |
... | @@ -36,19 +38,27 @@ app.post('/message', function(req,res){ | ... | @@ -36,19 +38,27 @@ app.post('/message', function(req,res){ |
36 | function(callback){ | 38 | function(callback){ |
37 | switch(msg){ | 39 | switch(msg){ |
38 | case 'Reol-Discography' : | 40 | case 'Reol-Discography' : |
39 | - singer = 'Reol' | 41 | + singer = 'Reol'; |
40 | - webcrawl.crawl_Reol('https://namu.wiki/w/%EB%A0%88%EC%98%A4%EB%A3%A8/%EC%9D%8C%EB%B0%98#toc',function(Reol){ | 42 | + crawlReol.crawl_Reol('https://namu.wiki/w/%EB%A0%88%EC%98%A4%EB%A3%A8/%EC%9D%8C%EB%B0%98#toc',function(Reol){ |
41 | callback(null,Reol); | 43 | callback(null,Reol); |
42 | - }) | 44 | + }); |
45 | + break; | ||
46 | + case '米津玄師-Discography' : | ||
47 | + singer = 'Yonezu'; | ||
48 | + crawlYonezu.crawl_yonezu('https://namu.wiki/w/%EC%9A%94%EB%84%A4%EC%A6%88%20%EC%BC%84%EC%8B%9C/%EB%94%94%EC%8A%A4%EC%BD%94%EA%B7%B8%EB%9E%98%ED%94%BC#s-3.2.9',function(yonezu){ | ||
49 | + callback(null,yonezu) | ||
50 | + }); | ||
43 | break; | 51 | break; |
44 | default: | 52 | default: |
45 | if(singer == 'Reol'){ | 53 | if(singer == 'Reol'){ |
46 | - webcrawl.crawl_Reol('https://namu.wiki/w/%EB%A0%88%EC%98%A4%EB%A3%A8/%EC%9D%8C%EB%B0%98#toc',function(Reol){ | 54 | + crawlReol.crawl_Reol('https://namu.wiki/w/%EB%A0%88%EC%98%A4%EB%A3%A8/%EC%9D%8C%EB%B0%98#toc',function(Reol){ |
47 | callback(null,Reol); | 55 | callback(null,Reol); |
48 | }) | 56 | }) |
49 | } | 57 | } |
50 | else if(singer == "Yonezu"){ | 58 | else if(singer == "Yonezu"){ |
51 | - | 59 | + crawlYonezu.crawl_yonezu('https://namu.wiki/w/%EC%9A%94%EB%84%A4%EC%A6%88%20%EC%BC%84%EC%8B%9C/%EB%94%94%EC%8A%A4%EC%BD%94%EA%B7%B8%EB%9E%98%ED%94%BC#s-3.2.9',function(yonezu){ |
60 | + callback(null,yonezu) | ||
61 | + }); | ||
52 | } | 62 | } |
53 | else | 63 | else |
54 | callback(null,null); | 64 | callback(null,null); |
... | @@ -170,7 +180,7 @@ app.post('/message', function(req,res){ | ... | @@ -170,7 +180,7 @@ app.post('/message', function(req,res){ |
170 | }, | 180 | }, |
171 | keyboard : { | 181 | keyboard : { |
172 | 'type' : 'buttons', | 182 | 'type' : 'buttons', |
173 | - 'buttons' : ['Reol', '米津玄師', 'yanaginagi', 'ヨルシカ', 'ダズビ', 'Polkadot Stingray', 'Aimyong'] | 183 | + 'buttons' : discography[0].json_album |
174 | } | 184 | } |
175 | 185 | ||
176 | }; | 186 | }; |
... | @@ -182,7 +192,7 @@ app.post('/message', function(req,res){ | ... | @@ -182,7 +192,7 @@ app.post('/message', function(req,res){ |
182 | }, | 192 | }, |
183 | keyboard : { | 193 | keyboard : { |
184 | 'type' : 'buttons', | 194 | 'type' : 'buttons', |
185 | - 'buttons' : ['한국', '일본'] | 195 | + 'buttons' : ['일본', '한국'] |
186 | } | 196 | } |
187 | } | 197 | } |
188 | break; | 198 | break; | ... | ... |
crawling/Yonezu.js
0 → 100644
1 | +var request = require('request'); | ||
2 | +var cheerio = require('cheerio'); | ||
3 | + | ||
4 | +function crawl_yonezu(url, callback){ | ||
5 | + let json_album = [], json_year = [], json_track = []; | ||
6 | + let yonezu = []; | ||
7 | + var track; | ||
8 | + var year; | ||
9 | + request(url, function (err, res, body) { | ||
10 | + const $ = cheerio.load(body); | ||
11 | + var kenshi = $('body > div.content-wrapper > article > div.wiki-content.clearfix > div') | ||
12 | + var index; | ||
13 | + for (var i = 1; i <= $('.toc-item').length; i++) { | ||
14 | + album = $(kenshi).find('#toc > div > div:nth-child(5) > div:nth-child(5) > span:nth-child(' + i + ')').text() //앨범 정보 가져오기 | ||
15 | + if (album != '') { | ||
16 | + json_album.push(album.substr(7)); | ||
17 | + } | ||
18 | + | ||
19 | + index = 40+i*2; | ||
20 | + var album_track = ''; | ||
21 | + var track_num = 0; | ||
22 | + var check = false; | ||
23 | + if($('body > div.content-wrapper > article > div.wiki-content.clearfix > div > div:nth-child('+index+')') != ''){ | ||
24 | + $('body > div.content-wrapper > article > div.wiki-content.clearfix > div > div:nth-child('+index+') > div > table > tbody').find('tr').each(function (index, ele) { | ||
25 | + track = $(this).children().eq(1).text(); | ||
26 | + if(check == true){ | ||
27 | + track_num++; | ||
28 | + album_track += track_num+'. '+track + '\n'; | ||
29 | + } | ||
30 | + if(track == '곡명') | ||
31 | + check = true; | ||
32 | + }); | ||
33 | + json_track.push(album_track); | ||
34 | + | ||
35 | + if(index == 44){ | ||
36 | + year = $('body > div.content-wrapper > article > div.wiki-content.clearfix > div > div:nth-child(44) > div:nth-child(3) > table > tbody > tr:nth-child(2) > td:nth-child(1)').children().eq(0).text(); | ||
37 | + year = year.substr(0,12) | ||
38 | + } | ||
39 | + else{ | ||
40 | + year = $('body > div.content-wrapper > article > div.wiki-content.clearfix > div > div:nth-child('+index+') > div > table > tbody > tr:nth-child(3)').children().eq(0).text(); | ||
41 | + year = year.substr(0,12) | ||
42 | + } | ||
43 | + json_year.push(year) | ||
44 | + } | ||
45 | + } | ||
46 | + | ||
47 | + yonezu.push({ json_album, json_year, json_track}); | ||
48 | + callback(yonezu); | ||
49 | + }); | ||
50 | +} | ||
51 | + | ||
52 | +exports.crawl_yonezu = crawl_yonezu; |
-
Please register or login to post a comment