Toggle navigation
Toggle navigation
This project
Loading...
Sign in
Chat_Bot
/
KaKao_ChatBot
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Graphs
Network
Create a new issue
Commits
Issue Boards
Authored by
윤준현
2018-12-04 21:02:09 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
318f73fb0e55be8b7144b4ed145da54fde11638e
318f73fb
1 parent
902c27c6
add Yonezu
success
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
70 additions
and
9 deletions
app.js
crawling/Reol.js
crawling/Yonezu.js
app.js
View file @
318f73f
...
...
@@ -4,8 +4,10 @@ var express = require('express');
var
http
=
require
(
'http'
);
var
bodyParser
=
require
(
'body-parser'
);
var
app
=
express
();
// express 객체 저장
var
webcrawl
=
require
(
'./crawling/Reol'
);
var
async
=
require
(
'async'
);
var
crawlReol
=
require
(
'./crawling/Reol'
);
var
crawlYonezu
=
require
(
'./crawling/Yonezu'
);
var
singer
;
//body-parser 미들웨어 사용
...
...
@@ -36,19 +38,27 @@ app.post('/message', function(req,res){
function
(
callback
){
switch
(
msg
){
case
'Reol-Discography'
:
singer
=
'Reol'
webcraw
l
.
crawl_Reol
(
'https://namu.wiki/w/%EB%A0%88%EC%98%A4%EB%A3%A8/%EC%9D%8C%EB%B0%98#toc'
,
function
(
Reol
){
singer
=
'Reol'
;
crawlReo
l
.
crawl_Reol
(
'https://namu.wiki/w/%EB%A0%88%EC%98%A4%EB%A3%A8/%EC%9D%8C%EB%B0%98#toc'
,
function
(
Reol
){
callback
(
null
,
Reol
);
})
});
break
;
case
'米津玄師-Discography'
:
singer
=
'Yonezu'
;
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
){
callback
(
null
,
yonezu
)
});
break
;
default
:
if
(
singer
==
'Reol'
){
webcraw
l
.
crawl_Reol
(
'https://namu.wiki/w/%EB%A0%88%EC%98%A4%EB%A3%A8/%EC%9D%8C%EB%B0%98#toc'
,
function
(
Reol
){
crawlReo
l
.
crawl_Reol
(
'https://namu.wiki/w/%EB%A0%88%EC%98%A4%EB%A3%A8/%EC%9D%8C%EB%B0%98#toc'
,
function
(
Reol
){
callback
(
null
,
Reol
);
})
}
else
if
(
singer
==
"Yonezu"
){
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
){
callback
(
null
,
yonezu
)
});
}
else
callback
(
null
,
null
);
...
...
@@ -170,7 +180,7 @@ app.post('/message', function(req,res){
},
keyboard
:
{
'type'
:
'buttons'
,
'buttons'
:
[
'Reol'
,
'米津玄師'
,
'yanaginagi'
,
'ヨルシカ'
,
'ダズビ'
,
'Polkadot Stingray'
,
'Aimyong'
]
'buttons'
:
discography
[
0
].
json_album
}
};
...
...
@@ -182,7 +192,7 @@ app.post('/message', function(req,res){
},
keyboard
:
{
'type'
:
'buttons'
,
'buttons'
:
[
'
한국'
,
'일본
'
]
'buttons'
:
[
'
일본'
,
'한국
'
]
}
}
break
;
...
...
crawling/Reol.js
View file @
318f73f
//Reol 나무위키 앨범 발매년도 트랙 크롤링
var
request
=
require
(
'request'
);
var
cheerio
=
require
(
'cheerio'
);
function
crawl_Reol
(
url
,
callback
){
...
...
crawling/Yonezu.js
0 → 100644
View file @
318f73f
var
request
=
require
(
'request'
);
var
cheerio
=
require
(
'cheerio'
);
function
crawl_yonezu
(
url
,
callback
){
let
json_album
=
[],
json_year
=
[],
json_track
=
[];
let
yonezu
=
[];
var
track
;
var
year
;
request
(
url
,
function
(
err
,
res
,
body
)
{
const
$
=
cheerio
.
load
(
body
);
var
kenshi
=
$
(
'body > div.content-wrapper > article > div.wiki-content.clearfix > div'
)
var
index
;
for
(
var
i
=
1
;
i
<=
$
(
'.toc-item'
).
length
;
i
++
)
{
album
=
$
(
kenshi
).
find
(
'#toc > div > div:nth-child(5) > div:nth-child(5) > span:nth-child('
+
i
+
')'
).
text
()
//앨범 정보 가져오기
if
(
album
!=
''
)
{
json_album
.
push
(
album
.
substr
(
7
));
}
index
=
40
+
i
*
2
;
var
album_track
=
''
;
var
track_num
=
0
;
var
check
=
false
;
if
(
$
(
'body > div.content-wrapper > article > div.wiki-content.clearfix > div > div:nth-child('
+
index
+
')'
)
!=
''
){
$
(
'body > div.content-wrapper > article > div.wiki-content.clearfix > div > div:nth-child('
+
index
+
') > div > table > tbody'
).
find
(
'tr'
).
each
(
function
(
index
,
ele
)
{
track
=
$
(
this
).
children
().
eq
(
1
).
text
();
if
(
check
==
true
){
track_num
++
;
album_track
+=
track_num
+
'. '
+
track
+
'\n'
;
}
if
(
track
==
'곡명'
)
check
=
true
;
});
json_track
.
push
(
album_track
);
if
(
index
==
44
){
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
();
year
=
year
.
substr
(
0
,
12
)
}
else
{
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
();
year
=
year
.
substr
(
0
,
12
)
}
json_year
.
push
(
year
)
}
}
yonezu
.
push
({
json_album
,
json_year
,
json_track
});
callback
(
yonezu
);
});
}
exports
.
crawl_yonezu
=
crawl_yonezu
;
Please
register
or
login
to post a comment