-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
94 lines (72 loc) · 2.44 KB
/
index.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
const express = require('express');
const app = express();
app.set('view engine', 'ejs');
const axios = require("axios");
const cheerio = require("cheerio");
const fs = require("fs");
app.use(express.static('public'));
app.listen((process.env.PORT || 8080) , function () {
console.log('listening on 8080');
});
app.get('/', function (req, res) {
let today = new Date();
let month = today.getMonth() + 1;
let date = today.getDate();
let hours = today.getHours();
let re = month + '월 ' + date + '일 ' + hours + ':00'
const parsing = async () => {
try {
return await axios.get("https://www.melon.com/chart/index.htm");
}
catch (error) {
console.error(error);
}
};
const data_list = []
parsing()
.then(html => {
let ulList = [];
const $ = cheerio.load(html.data);
const $bodyList = $("form#frm")
.children(".service_list_song")
.children("table")
.children("tbody")
.children("tr")
$bodyList.each(function(i, element) {
ulList[i] = {
rank: $(this).find(
'td div.t_center span.rank'
).text(),
title: $(this).find(
'td div.wrap div.wrap_song_info div.rank01 span a'
).text(),
artist: $(this).find(
'td div.wrap div.wrap_song_info div.rank02 span a'
).text(),
image_url: $(this).find(
'td div.wrap a.image_typeAll img'
).attr('src'),
rank_move: $(this).find(
'td div.wrap span.rank_wrap span.bullet_icons span.none',
).text(),
up_value: $(this).find(
'td div.wrap span.rank_wrap span.up',
).text(),
down_value: $(this).find(
'td div.wrap span.rank_wrap span.down',
).text(),
};
});
const data = ulList.filter(n => (n.artist === '임영웅'));
return data;
}
)
.then(res => {
console.log(res);
this.data_list = res;
});
res.render('../index.ejs', {
data: this.data_list,
time: re
});
});