권은령

update genie music crawling

var cheerio = require('cheerio');
var request = require('request');
var url="http://www.melcon.com/chart/";
var url="https://www.genie.co.kr/chart/top200";
request(url, function(error, response, html)
{
var $ = cheerio.load(html);
var arr=$('.ellipsis rank01');
console.log(arr[0].children[0].attribs.title);
var songList=[];
const $bodyList= $('#body-content > div.newest-list > div > table > tbody > tr');
console.log($bodyList.length);
$bodyList.each(function(i, elem)
{
if(i<20)
{
songList.push(
{
singer: $(this).find("td.info").find("a.artist.ellipsis").text().trim(),
song: $(this).find("td.info").find("a.title.ellipsis").text().trim(),
url: 'https://www.genie.co.kr/detail/songInfo?xgnm='+$(this).attr("songid")
}
);
}
else
{
return;
}
})
for(var i=0; i<songList.length; i++)
{
console.log(songList[i]);
}
var randnum=function getRandomInt(min, max)
{
min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(Math.random() * (max - min)) + min; //최댓값은 제외, 최솟값은 포함
}(0, 20);
console.log(randnum);
var newUrl=songList[randnum].url;
})
request(newUrl, function(error, response, html)
{
var $ = cheerio.load(html);
console.log(songList[randnum].song);
console.log($('#pLyrics > p').text());
});
})
\ No newline at end of file
......