Showing
3 changed files
with
95 additions
and
8 deletions
| ... | @@ -8,6 +8,7 @@ var async = require('async'); | ... | @@ -8,6 +8,7 @@ var async = require('async'); |
| 8 | 8 | ||
| 9 | var crawlReol = require('./crawling/Reol'); | 9 | var crawlReol = require('./crawling/Reol'); |
| 10 | var crawlYonezu = require('./crawling/Yonezu'); | 10 | var crawlYonezu = require('./crawling/Yonezu'); |
| 11 | +var crawlYorusika = require('./crawling/Yorusika'); | ||
| 11 | var singer; | 12 | var singer; |
| 12 | 13 | ||
| 13 | //body-parser 미들웨어 사용 | 14 | //body-parser 미들웨어 사용 |
| ... | @@ -51,7 +52,10 @@ app.post('/message', function(req,res){ | ... | @@ -51,7 +52,10 @@ app.post('/message', function(req,res){ |
| 51 | break; | 52 | break; |
| 52 | case 'ヨルシカ-Discography' : | 53 | case 'ヨルシカ-Discography' : |
| 53 | singer = 'yorusika'; | 54 | singer = 'yorusika'; |
| 54 | - break | 55 | + crawlYorusika.crawl_yorusika('http://yorushika.com/discography/', function(yorusika){ |
| 56 | + callback(null,yorusika); | ||
| 57 | + }); | ||
| 58 | + break; | ||
| 55 | default: | 59 | default: |
| 56 | if(singer == 'Reol'){ | 60 | if(singer == 'Reol'){ |
| 57 | 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){ | 61 | 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){ |
| ... | @@ -64,7 +68,9 @@ app.post('/message', function(req,res){ | ... | @@ -64,7 +68,9 @@ app.post('/message', function(req,res){ |
| 64 | }); | 68 | }); |
| 65 | } | 69 | } |
| 66 | else if(singer=='yorusika'){ | 70 | else if(singer=='yorusika'){ |
| 67 | - | 71 | + crawlYorusika.crawl_yorusika('http://yorushika.com/discography/', function(yorusika){ |
| 72 | + callback(null,yorusika); | ||
| 73 | + }); | ||
| 68 | } | 74 | } |
| 69 | else | 75 | else |
| 70 | callback(null,null); | 76 | callback(null,null); |
| ... | @@ -124,7 +130,16 @@ app.post('/message', function(req,res){ | ... | @@ -124,7 +130,16 @@ app.post('/message', function(req,res){ |
| 124 | case 'Reol-Discography' : | 130 | case 'Reol-Discography' : |
| 125 | send = { | 131 | send = { |
| 126 | 'message': { | 132 | 'message': { |
| 127 | - 'text': '앨범 목록입니다.' | 133 | + 'text': 'Album List', |
| 134 | + 'photo': { | ||
| 135 | + 'url': 'https://yt3.ggpht.com/a-/AN66SAydQt1STVdFCVvwEyZitr-v4dNGDKdyIt-oSA=s288-mo-c-c0xffffffff-rj-k-no', | ||
| 136 | + 'width': 300, | ||
| 137 | + 'height': 300 | ||
| 138 | + }, | ||
| 139 | + 'message_button' : { | ||
| 140 | + 'label' : 'Youtube channel Link', | ||
| 141 | + 'url' : "https://www.youtube.com/channel/UCB6pJFaFByws3dQj4AdLdyA/" | ||
| 142 | + } | ||
| 128 | }, | 143 | }, |
| 129 | keyboard: { | 144 | keyboard: { |
| 130 | 'type': 'buttons', | 145 | 'type': 'buttons', |
| ... | @@ -138,7 +153,7 @@ app.post('/message', function(req,res){ | ... | @@ -138,7 +153,7 @@ app.post('/message', function(req,res){ |
| 138 | 'message': { | 153 | 'message': { |
| 139 | 'text': '이름 : 米津玄師(Yonezu Kenshi) \n성별 : 남성 \n생년월일 : 1991년 3월 10일 \n혈액형 : O형', | 154 | 'text': '이름 : 米津玄師(Yonezu Kenshi) \n성별 : 남성 \n생년월일 : 1991년 3월 10일 \n혈액형 : O형', |
| 140 | 'photo': { | 155 | 'photo': { |
| 141 | - 'url': 'http://reissuerecords.net/rr/wp-content/uploads/flamingo_photo2.jpg', | 156 | + 'url': 'https://s3.namuwikiusercontent.com/s/5f35be0c28de612d20eccea8c795cee38eea58700af4723f6920fc00b48c491ae5e89572e7bcb5ab2e2eb37aa6c498dbc3f4896239d3f98e4794c9b1ec96031c43d77090d83f00ba5b7d65e566f415af055f79a8059dd2f6b1f36f0f8e742f9d', |
| 142 | 'width': 1000, | 157 | 'width': 1000, |
| 143 | 'height': 667 | 158 | 'height': 667 |
| 144 | }, | 159 | }, |
| ... | @@ -156,7 +171,16 @@ app.post('/message', function(req,res){ | ... | @@ -156,7 +171,16 @@ app.post('/message', function(req,res){ |
| 156 | case '米津玄師-Discography': | 171 | case '米津玄師-Discography': |
| 157 | send = { | 172 | send = { |
| 158 | 'message': { | 173 | 'message': { |
| 159 | - 'text': 'Album List' | 174 | + 'text': 'Album List', |
| 175 | + 'photo': { | ||
| 176 | + 'url': 'https://yt3.ggpht.com/a-/AN66SAwKDZ2RTvreg5m1Ub6Wd6glpKCYMGrVG4mpqw=s288-mo-c-c0xffffffff-rj-k-no', | ||
| 177 | + 'width': 300, | ||
| 178 | + 'height': 300 | ||
| 179 | + }, | ||
| 180 | + 'message_button' : { | ||
| 181 | + 'label' : 'Youtube channel Link', | ||
| 182 | + 'url' : "https://www.youtube.com/channel/UCUCeZaZeJbEYAAzvMgrKOPQ/" | ||
| 183 | + } | ||
| 160 | }, | 184 | }, |
| 161 | keyboard: { | 185 | keyboard: { |
| 162 | 'type': 'buttons', | 186 | 'type': 'buttons', |
| ... | @@ -188,11 +212,20 @@ app.post('/message', function(req,res){ | ... | @@ -188,11 +212,20 @@ app.post('/message', function(req,res){ |
| 188 | case 'ヨルシカ-Discography': | 212 | case 'ヨルシカ-Discography': |
| 189 | send = { | 213 | send = { |
| 190 | 'message': { | 214 | 'message': { |
| 191 | - 'text': 'Album List' | 215 | + 'text': 'Album List', |
| 216 | + 'photo': { | ||
| 217 | + 'url': 'https://yt3.ggpht.com/a-/AN66SAzKliDeZQJhb9JshzY4hJY_pJSbM1gfYoqY=s288-mo-c-c0xffffffff-rj-k-no', | ||
| 218 | + 'width': 300, | ||
| 219 | + 'height': 300 | ||
| 220 | + }, | ||
| 221 | + 'message_button' : { | ||
| 222 | + 'label' : 'Youtube channel Link', | ||
| 223 | + 'url' : "https://www.youtube.com/channel/UCRIgIJQWuBJ0Cv_VlU3USNA" | ||
| 224 | + } | ||
| 192 | }, | 225 | }, |
| 193 | keyboard: { | 226 | keyboard: { |
| 194 | 'type': 'buttons', | 227 | 'type': 'buttons', |
| 195 | - 'buttons': ['ㅁ'] | 228 | + 'buttons': discography[0].json_album |
| 196 | } | 229 | } |
| 197 | 230 | ||
| 198 | }; | 231 | }; | ... | ... |
| ... | @@ -10,10 +10,13 @@ function crawl_yonezu(url, callback){ | ... | @@ -10,10 +10,13 @@ function crawl_yonezu(url, callback){ |
| 10 | const $ = cheerio.load(body); | 10 | const $ = cheerio.load(body); |
| 11 | var kenshi = $('body > div.content-wrapper > article > div.wiki-content.clearfix > div') | 11 | var kenshi = $('body > div.content-wrapper > article > div.wiki-content.clearfix > div') |
| 12 | var index; | 12 | var index; |
| 13 | + var album_num = 0; | ||
| 13 | for (var i = 1; i <= $('.toc-item').length; i++) { | 14 | 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 | album = $(kenshi).find('#toc > div > div:nth-child(5) > div:nth-child(5) > span:nth-child(' + i + ')').text() //앨범 정보 가져오기 |
| 15 | if (album != '') { | 16 | if (album != '') { |
| 16 | - json_album.push(album.substr(7)); | 17 | + album_num++ |
| 18 | + album = album_num+'.'+album.substr(14) | ||
| 19 | + json_album.push(album); | ||
| 17 | } | 20 | } |
| 18 | 21 | ||
| 19 | index = 40+i*2; | 22 | index = 40+i*2; | ... | ... |
crawling/Yorusika.js
0 → 100644
| 1 | +var request = require('request'); | ||
| 2 | +var cheerio = require('cheerio'); | ||
| 3 | + | ||
| 4 | +function crawl_yorusika(url, callback){ | ||
| 5 | + let json_album = [], json_year = [], json_track = [], json_image = []; | ||
| 6 | + let yorusika = []; | ||
| 7 | + var track; | ||
| 8 | + var year; | ||
| 9 | + request(url, function (err, res, body) { | ||
| 10 | + const $ = cheerio.load(body); | ||
| 11 | + var index; | ||
| 12 | + var album_num = 0; | ||
| 13 | + console.log($('.discography_contents').length); | ||
| 14 | + for (var i = $('.discography_contents').length; i >=1; i--) { | ||
| 15 | + year = $('body > article > section > div > div:nth-child('+i+') > div.discography_text > div.discography_date').text(); | ||
| 16 | + year = year.substr(0,year.length-7); | ||
| 17 | + json_year.push(year); | ||
| 18 | + | ||
| 19 | + if(i == 3){ | ||
| 20 | + track = $('body > article > section > div > div:nth-child('+i+') > div.discography_text > div.discography_description').text(); | ||
| 21 | + track = track.substr(6); | ||
| 22 | + track = track.substr(0,track.length-22); | ||
| 23 | + } | ||
| 24 | + else{ | ||
| 25 | + track = $('body > article > section > div > div:nth-child('+i+') > div.discography_text > div.discography_description').text(); | ||
| 26 | + track = track.substr(6); | ||
| 27 | + track = track.substr(0,track.length-7); | ||
| 28 | + } | ||
| 29 | + json_track.push(track); | ||
| 30 | + | ||
| 31 | + var check = false | ||
| 32 | + album_num++; | ||
| 33 | + var album_name = ''; | ||
| 34 | + album = $('body > article > section > div > div:nth-child('+i+') > div.discography_text > div.discography_title').text(); | ||
| 35 | + for(var j = 0; j<album.length;j++){ | ||
| 36 | + if(album[j] == '「') | ||
| 37 | + check = true; | ||
| 38 | + if(check == true) | ||
| 39 | + album_name += album[j]; | ||
| 40 | + } | ||
| 41 | + album_name = album_num + '. ' + album_name | ||
| 42 | + json_album.push(album_name); | ||
| 43 | + | ||
| 44 | + } | ||
| 45 | + | ||
| 46 | + yorusika.push({ json_album, json_year, json_track}); | ||
| 47 | + callback(yorusika); | ||
| 48 | + }); | ||
| 49 | +} | ||
| 50 | + | ||
| 51 | +exports.crawl_yorusika = crawl_yorusika; | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
-
Please register or login to post a comment