forked from 1core2life/smart-mirror-A-team
-
Notifications
You must be signed in to change notification settings - Fork 0
/
news.js
executable file
·58 lines (52 loc) · 1.5 KB
/
news.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
exports.news_result = function(res) {
var request = require("request");
var cheerio = require('cheerio');
var iconv = require('iconv-lite');
var dt = new Date();
var month = dt.getMonth()+1;
if(month<10)
{
month="0"+month;
}
var day = dt.getDate();
if(day<10)
{
day="0"+day;
}
var year = dt.getFullYear();
request({
url: 'http://news.naver.com/main/ranking/popularDay.nhn?rankingType=popular_day§ionId=000&date='+year+month+day,
method: 'GET',
encoding: null
}, function(err, response, body) {
var title=new Array();
var writer=new Array();
var date=new Array();
iconv.extendNodeEncodings();
var strContents = new Buffer(body);
$ = cheerio.load(iconv.decode(strContents, 'EUC-KR').toString());
//console.log($('.list_body.newsflash_body').html()); // 기사 목록을 출력
result = [];
$('.ranking_top3.ranking_top3_v2').find('li').each(function(index, ele) {
var dt1 = $(this).eq(0);
title.push(dt1.find('a').text());
var dd = $(this).find('dd').eq(0);
var temp=dd.find('span').text().trim();
temp=temp.split('|');
writer.push(temp[0]);
date.push(temp[1]);
});
$('.ranking_section.ranfir2').find('li').each(function(index, ele) {
var dt1 = $(this).eq(0);
title.push(dt1.find('a').text());
var dd = $(this).find('span').eq(0).text().trim();
writer.push(dd);
});
console.log(title);
console.log(writer);
res.render('new_result', {
news: title,
writer: writer
});
});
};