janghak1.js
1.26 KB
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
const axios = require("axios");
const cheerio = require("cheerio");
const Iconv = require("iconv").Iconv;
var iconv = new Iconv('euc-kr', 'UTF-8//translit//ignore');
var getHTML = async function(link){
try{
return await axios.request({
method: 'GET',
url: link,
responseType: "arraybuffer",
responseEncoding: "binary"
})
} catch(e){
console.log(e);
}
}
async function getList(link){
list = [];
HTML = await getHTML(link);
body = iconv.convert(HTML.data);
var $ = cheerio.load(body);
var titleList = $('.bg1');
titleList.each(function(i, elem){
list[i] = {
title: $(this).find(".subject").text().replace(/(\r\n\t|\n|\r\t)/gm,"").replace(/(^\s*)|(\s*$)/gi, ""),
link: "http://janghak.khu.ac.kr/board" + $(this).find("a").attr('href').substr(2),
date: $(this).find(".datetime").text().replace(/(\r\n\t|\n|\r\t)/gm,"").replace(/(^\s*)|(\s*$)/gi, ""),
site: '경희대학교 장학센터'
}
})
list = list.filter(item => item.title);
return list
}
async function loading(){
li = await getList('http://janghak.khu.ac.kr/board/bbs/board.php?bo_table=06_01');
return li;
}
module.exports.loading = loading;