Showing
4 changed files
with
20 additions
and
43 deletions
webcrawling-practice/notepad.js
0 → 100644
File mode changed
... | @@ -9,10 +9,11 @@ var getHTML = async function(link){ | ... | @@ -9,10 +9,11 @@ var getHTML = async function(link){ |
9 | } | 9 | } |
10 | } | 10 | } |
11 | 11 | ||
12 | -getHTML("http://software.khu.ac.kr/board5/bbs/board.php?bo_table=05_01&page=1").then(function(HTML){ | 12 | +async function getList(link){ |
13 | + list = []; | ||
14 | + HTML = await getHTML(link); | ||
13 | var $ = cheerio.load(HTML.data); | 15 | var $ = cheerio.load(HTML.data); |
14 | var titleList = $('tr'); | 16 | var titleList = $('tr'); |
15 | - var list = []; | ||
16 | titleList.each(function(i, elem){ | 17 | titleList.each(function(i, elem){ |
17 | list[i] = { | 18 | list[i] = { |
18 | title: $(this).find(".bo_tit").text().replace(/(\r\n\t|\n|\r\t)/gm,"").replace(/(^\s*)|(\s*$)/gi, ""), | 19 | title: $(this).find(".bo_tit").text().replace(/(\r\n\t|\n|\r\t)/gm,"").replace(/(^\s*)|(\s*$)/gi, ""), |
... | @@ -21,24 +22,13 @@ getHTML("http://software.khu.ac.kr/board5/bbs/board.php?bo_table=05_01&page=1"). | ... | @@ -21,24 +22,13 @@ getHTML("http://software.khu.ac.kr/board5/bbs/board.php?bo_table=05_01&page=1"). |
21 | site: '소프트웨어 융합대학 공지사항' | 22 | site: '소프트웨어 융합대학 공지사항' |
22 | } | 23 | } |
23 | }) | 24 | }) |
24 | -}); | 25 | + list = list.filter(item => item.title); |
25 | -getHTML("http://software.khu.ac.kr/board5/bbs/board.php?bo_table=05_01&page=2").then(function(HTML){ | 26 | + return list |
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 | } | 27 | } |
43 | 28 | ||
29 | +async function loading(){ | ||
30 | + li = await getList('http://software.khu.ac.kr/board5/bbs/board.php?bo_table=05_01&page=1'); | ||
31 | + console.log(li); | ||
32 | +} | ||
44 | 33 | ||
34 | +module.exports.loading = loading; | ... | ... |
1 | 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 |
2 | +console.log('2019-01-31' < '2019-01-01'); | ||
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
-
Please register or login to post a comment