-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
34 lines (32 loc) · 1.06 KB
/
app.js
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
const rp = require('request-promise');
const cheerio = require('cheerio'); // Basically jQuery for node.js
const list = [];
const naver = url => rp({uri: url, transform: body => cheerio.load(body)})
.then($ => {
$('div[class="ah_list PM_CL_realtimeKeyword_list_base"]').find('ul > li > a[class=ah_a]').each((index, element) => {
if(index < 10){
list.push($(element).attr('href'));
// console.log($(element).find('.ah_k').text())
}
});
return list;
})
.then(list => {
const relUrl = list.map(element => {
return rp({uri: element}).then(htmlString => htmlString);
})
return Promise.all(relUrl).then(values => {
return values.map(ele => {
const $ = cheerio.load(ele);
const relation = []
$('ul[class=_related_keyword_ul]').find('li > a').each((index, element) => {
relation.push($(element).text());
})
return relation;
})
})
})
.catch(err => {
console.log(err);
});
module.exports = naver;