Toggle navigation
Toggle navigation
This project
Loading...
Sign in
이태화
/
khu-notice-project
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
이태화
2020-10-30 20:45:59 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
ff8962e4338c900e0dbc31e67721e729eee5fff8
ff8962e4
1 parent
abf264d1
async test
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
68 additions
and
35 deletions
webcrawling-practice/main.js
webcrawling-practice/swuniv.js
webcrawling-practice/syncTest.js
webcrawling-practice/main.js
View file @
ff8962e
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
);
...
...
webcrawling-practice/swuniv.js
0 → 100644
View file @
ff8962e
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
]);
}
webcrawling-practice/syncTest.js
0 → 100644
View file @
ff8962e
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
Please
register
or
login
to post a comment