janghak1.js 1.26 KB
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;