이태화

async test

const express = require("express");
const App = express();
const axios = require("axios");
const cheerio = require("cheerio");
const swuniv = require('./swuniv.js');
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)
\ No newline at end of file
console.log(swuniv);
......
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]);
}
function fetchItem(){
return new Promise(function(resolve,reject){
setTimeout(function(){
resolve();
console.log("resolved");
},3000)
})
}
async function hello(){
await fetchItem();
await fetchItem();
await fetchItem();
await fetchItem();
await fetchItem();
await fetchItem();
console.log("resolve Complete")
}
hello();
\ No newline at end of file