이태화

async test

1 -const express = require("express"); 1 +const swuniv = require('./swuniv.js');
2 -const App = express();
3 -const axios = require("axios");
4 -const cheerio = require("cheerio");
5 2
6 -App.get('/',function(req,res){
7 - res.send('hello');
8 -})
9 -
10 -var getHTML = async function(){
11 - try{
12 - return await axios.get("http://software.khu.ac.kr/board5/bbs/board.php?bo_table=05_01&page=1");
13 - } catch(e){
14 - console.log(e);
15 - }
16 -}
17 -
18 -getHTML().then(function(HTML){
19 - var list = [];
20 - var $ = cheerio.load(HTML.data);
21 - var titleList = $('tr');
22 - titleList.each(function(i, elem){
23 - list[i] = {
24 - title: $(this).find(".bo_tit").text().replace(/(\r\n\t|\n|\r\t)/gm,"").replace(/(^\s*)|(\s*$)/gi, "")
25 - }
26 - })
27 - for(var i = 0; i < list.length;i++){
28 - console.log(list[i]);
29 - }
30 -
31 -
32 -}
33 -);
34 -
35 -
36 -App.listen(80)
...\ No newline at end of file ...\ No newline at end of file
3 +console.log(swuniv);
......
1 +const axios = require("axios");
2 +const cheerio = require("cheerio");
3 +
4 +var getHTML = async function(link){
5 + try{
6 + return await axios.get(link);
7 + } catch(e){
8 + console.log(e);
9 + }
10 +}
11 +
12 +getHTML("http://software.khu.ac.kr/board5/bbs/board.php?bo_table=05_01&page=1").then(function(HTML){
13 + var $ = cheerio.load(HTML.data);
14 + var titleList = $('tr');
15 + var list = [];
16 + titleList.each(function(i, elem){
17 + list[i] = {
18 + title: $(this).find(".bo_tit").text().replace(/(\r\n\t|\n|\r\t)/gm,"").replace(/(^\s*)|(\s*$)/gi, ""),
19 + link: $(this).find("a").attr('href').replace(/(\r\n\t|\n|\r\t)/gm,"").replace(/(^\s*)|(\s*$)/gi, ""),
20 + date: $(this).find(".td_datetime").text().replace(/(\r\n\t|\n|\r\t)/gm,"").replace(/(^\s*)|(\s*$)/gi, ""),
21 + site: '소프트웨어 융합대학 공지사항'
22 + }
23 + })
24 +});
25 +getHTML("http://software.khu.ac.kr/board5/bbs/board.php?bo_table=05_01&page=2").then(function(HTML){
26 + var $ = cheerio.load(HTML.data);
27 + var titleList = $('tr');
28 + var list = [];
29 + titleList.each(function(i, elem){
30 + list[i] = {
31 + title: $(this).find(".bo_tit").text().replace(/(\r\n\t|\n|\r\t)/gm,"").replace(/(^\s*)|(\s*$)/gi, ""),
32 + link: $(this).find("a").attr('href').replace(/(\r\n\t|\n|\r\t)/gm,"").replace(/(^\s*)|(\s*$)/gi, ""),
33 + date: $(this).find(".td_datetime").text().replace(/(\r\n\t|\n|\r\t)/gm,"").replace(/(^\s*)|(\s*$)/gi, ""),
34 + site: '소프트웨어 융합대학 공지사항'
35 + }
36 + })
37 +});
38 +
39 +for(var i =0;i<list.length;i++){
40 + console.log(i);
41 + console.log(list[i]);
42 +}
43 +
44 +
1 +
2 +function fetchItem(){
3 + return new Promise(function(resolve,reject){
4 + setTimeout(function(){
5 + resolve();
6 + console.log("resolved");
7 + },3000)
8 + })
9 +}
10 +
11 +
12 +async function hello(){
13 + await fetchItem();
14 + await fetchItem();
15 + await fetchItem();
16 + await fetchItem();
17 + await fetchItem();
18 + await fetchItem();
19 + console.log("resolve Complete")
20 +}
21 +
22 +hello();
...\ No newline at end of file ...\ No newline at end of file