swuniv.js 1.6 KB
const axios = require("axios");
const cheerio = require("cheerio");

var getHTML = async function(link){
    try{
        return await axios.get(link);
    } catch(e){
        console.log(e);
    }
}

getHTML("http://software.khu.ac.kr/board5/bbs/board.php?bo_table=05_01&page=1").then(function(HTML){
    var $ = cheerio.load(HTML.data);
    var titleList = $('tr');
    var list = [];
    titleList.each(function(i, elem){
        list[i] = {
            title: $(this).find(".bo_tit").text().replace(/(\r\n\t|\n|\r\t)/gm,"").replace(/(^\s*)|(\s*$)/gi, ""),
            link: $(this).find("a").attr('href').replace(/(\r\n\t|\n|\r\t)/gm,"").replace(/(^\s*)|(\s*$)/gi, ""),
            date: $(this).find(".td_datetime").text().replace(/(\r\n\t|\n|\r\t)/gm,"").replace(/(^\s*)|(\s*$)/gi, ""),
            site: '소프트웨어 융합대학 공지사항'
        }
    })
});
getHTML("http://software.khu.ac.kr/board5/bbs/board.php?bo_table=05_01&page=2").then(function(HTML){
    var $ = cheerio.load(HTML.data);
    var titleList = $('tr');
    var list = [];
    titleList.each(function(i, elem){
        list[i] = {
            title: $(this).find(".bo_tit").text().replace(/(\r\n\t|\n|\r\t)/gm,"").replace(/(^\s*)|(\s*$)/gi, ""),
            link: $(this).find("a").attr('href').replace(/(\r\n\t|\n|\r\t)/gm,"").replace(/(^\s*)|(\s*$)/gi, ""),
            date: $(this).find(".td_datetime").text().replace(/(\r\n\t|\n|\r\t)/gm,"").replace(/(^\s*)|(\s*$)/gi, ""),
            site: '소프트웨어 융합대학 공지사항'
        }
    })
});

for(var i =0;i<list.length;i++){
    console.log(i);
    console.log(list[i]);
}