Showing
1 changed file
with
15 additions
and
24 deletions
... | @@ -97,26 +97,20 @@ async function handleEvent(event) { | ... | @@ -97,26 +97,20 @@ async function handleEvent(event) { |
97 | }; | 97 | }; |
98 | 98 | ||
99 | request.post(options, function (error, response, body) { | 99 | request.post(options, function (error, response, body) { |
100 | - let jsonResponse = JSON.stringify(JSON.parse(body), null, ' '); | 100 | + var data=JSON.stringify(body); |
101 | - jsonResponse=jsonResponse.toString() | 101 | + var text=''; |
102 | - text=''; | 102 | + while(data.indexOf('text\\')!=-1) |
103 | - while(jsonResponse.indexOf('text')!=-1) | ||
104 | { | 103 | { |
105 | - jsonResponse=jsonResponse.substring(jsonResponse.indexOf('text\\')+9); | 104 | + data=data.substring(data.indexOf('text\\')+9); |
106 | - text+=jsonResponse.substring(0,jsonResponse.indexOf("\\"))+" "; | 105 | + text+=data.substring(0,data.indexOf("\\"))+" "; |
107 | - | ||
108 | - } | ||
109 | - | ||
110 | - text.replace('\n',''); | ||
111 | - if(text.length>20) | ||
112 | - { | ||
113 | - text=text.substring(text.length/6,text.length/4); | ||
114 | } | 106 | } |
107 | + text=text.substring(text.length/10+1,text.length/8+2); | ||
115 | console.log(text); | 108 | console.log(text); |
116 | - var url="https://www.genie.co.kr/search/searchLyrics?query="+ encodeURI(text); | 109 | + var url="https://www.genie.co.kr/search/searchLyrics?query="+text; |
117 | - request(url, function(error, response, html){ | 110 | + request(url, function(error, response, html) |
111 | + { | ||
112 | + console.log(url); | ||
118 | var $ = cheerio.load(html); | 113 | var $ = cheerio.load(html); |
119 | - | ||
120 | const $bodyList= $('#body-content > div.search_lyrics > div.music-list-wrap.type-lyrics > table > tbody > tr'); | 114 | const $bodyList= $('#body-content > div.search_lyrics > div.music-list-wrap.type-lyrics > table > tbody > tr'); |
121 | 115 | ||
122 | var songList=[]; | 116 | var songList=[]; |
... | @@ -128,20 +122,17 @@ async function handleEvent(event) { | ... | @@ -128,20 +122,17 @@ async function handleEvent(event) { |
128 | }); | 122 | }); |
129 | 123 | ||
130 | } | 124 | } |
131 | - console.log(songList); | ||
132 | }) | 125 | }) |
133 | - var result=''; | 126 | + var resultm=''; |
134 | for(var i=0;i<songList.length;i++){ | 127 | for(var i=0;i<songList.length;i++){ |
135 | if(songList[i].singer!=''){ | 128 | if(songList[i].singer!=''){ |
136 | - result+=songList[i].singer+", "+songList[i].song+"\n"; | 129 | + resultm+=songList[i].singer+", "+songList[i].song+"\n"; |
137 | } | 130 | } |
138 | - console.log(result); | ||
139 | } | 131 | } |
140 | - client.replyMessage(event.replyToken,result).then(resolve).catch(reject); | 132 | + console.log(resultm); |
141 | - }); | ||
142 | - }); | ||
143 | - | ||
144 | }); | 133 | }); |
134 | + | ||
135 | + }); | ||
145 | 136 | ||
146 | } | 137 | } |
147 | else if(event.type == 'message' && event.message.type == 'text') | 138 | else if(event.type == 'message' && event.message.type == 'text') | ... | ... |
-
Please register or login to post a comment