main.js 785 Bytes
const express = require("express");
const App = express();
const axios = require("axios");
const cheerio = require("cheerio");

App.get('/',function(req,res){
    res.send('hello');
})

var getHTML = async function(){
    try{
        return await axios.get("http://software.khu.ac.kr/board5/bbs/board.php?bo_table=05_01&page=1");
    } catch(e){
        console.log(e);
    }
}

getHTML().then(function(HTML){
    var list = [];
    var $ = cheerio.load(HTML.data);
    var titleList = $('tr');
    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, "")
        }
    })
    for(var i = 0; i < list.length;i++){
        console.log(list[i]);
    }


}
);


App.listen(80)