Toggle navigation
Toggle navigation
This project
Loading...
Sign in
정승우
/
YaguMoa
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
1
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
진성욱
2020-06-15 18:07:18 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
9132c113b53096bef7185dcd76b09ea65f9cadb7
9132c113
1 parent
1beceb5d
비동기를 통한 데이터 처리
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
83 additions
and
33 deletions
testcode/@
testcode/routes/index.js
testcode/test1.js
testcode/test2.js
testcode/test3.js
testcode/testlist.js
testcode/views/index.ejs
testcode/@
0 → 100644
View file @
9132c11
var express = require('express');
var router = express.Router();
const Xports = require('../test1.js');
const Zum = require('../test2.js');
const Chosun = require('../test3.js');
const zum = Zum.zum;
const chosun = Chosun.chosun;
exports().then(a => {
console.log(a);
});
const xports = new Array();
router.get('/', function(req, res, next){
res.render('index', {
xports : xports,
zum : zum,
chosun : chosun,
// yna : yna
});
});
console.log("aaaa\n");
for(var i in xports){
console.log("aaaa\n");
console.log(i.datetime);
}
module.exports = router;
testcode/routes/index.js
View file @
9132c11
var
express
=
require
(
'express'
);
var
router
=
express
.
Router
();
const
Xports
=
require
(
'../test1.js'
);
const
get
Xports
=
require
(
'../test1.js'
);
const
Zum
=
require
(
'../test2.js'
);
const
Chosun
=
require
(
'../test3.js'
);
const
Yna
=
require
(
'../test4.js'
);
const
xports
=
Xports
.
xports
;
const
zum
=
Zum
.
zum
;
const
chosun
=
Chosun
.
chosun
;
const
yna
=
Yna
.
yna
;
let
xports
;
(
async
function
()
{
try
{
xports
=
await
getXports
();
console
.
log
(
xports
);
}
catch
(
e
)
{
return
console
.
log
(
e
);
}
})();
router
.
get
(
'/'
,
function
(
req
,
res
,
next
){
...
...
@@ -16,11 +23,13 @@ router.get('/', function(req, res, next){
xports
:
xports
,
zum
:
zum
,
chosun
:
chosun
,
yna
:
yna
//
yna : yna
});
});
console
.
log
(
"aaaa\n"
);
for
(
var
i
in
xports
){
console
.
log
(
"aaaa\n"
);
console
.
log
(
i
.
datetime
);
}
module
.
exports
=
router
;
\ No newline at end of file
module
.
exports
=
router
;
...
...
testcode/test1.js
View file @
9132c11
...
...
@@ -13,25 +13,35 @@ const getHtml = async () => {
}
};
getHtml
()
.
then
(
html
=>
{
let
ulList
=
[];
//console.log(html.data);
const
$
=
cheerio
.
load
(
html
.
data
);
const
$bodyList
=
$
(
"ul.list_news > li"
);
//.children("");
$bodyList
.
each
(
function
(
i
,
elem
)
{
ulList
[
i
]
=
{
url
:
'xportsnews.com'
+
$
(
this
).
find
(
'div.thumb > a'
).
attr
(
'href'
),
image_url
:
$
(
this
).
find
(
'div.thumb > a > img'
).
attr
(
'src'
),
title
:
$
(
this
).
find
(
'dl.dlist > dt > a'
).
text
(),
summary
:
$
(
this
).
find
(
'dd'
).
text
().
slice
(
1
,
-
2
),
datetime
:
$
(
this
).
find
(
'dd > span.data'
).
text
()
};
//console.log(ulList[i]) // list object checking code
});
const
data
=
ulList
.
filter
(
n
=>
n
.
title
);
return
data
;
//return ulList;
}).
then
(
res
=>
console
.
log
(
res
));
\ No newline at end of file
const
getXports
=
async
()
=>
{
return
new
Promise
((
resolve
,
reject
)
=>
{
getHtml
()
.
then
(
html
=>
{
let
ulList
=
[];
//console.log(html.data);
const
$
=
cheerio
.
load
(
html
.
data
);
const
$bodyList
=
$
(
"ul.list_news > li"
);
//.children("");
$bodyList
.
each
(
function
(
i
,
elem
)
{
ulList
[
i
]
=
{
url
:
'xportsnews.com'
+
$
(
this
).
find
(
'div.thumb > a'
).
attr
(
'href'
),
image_url
:
$
(
this
).
find
(
'div.thumb > a > img'
).
attr
(
'src'
),
title
:
$
(
this
).
find
(
'dl.dlist > dt > a'
).
text
(),
summary
:
$
(
this
).
find
(
'dd'
).
text
().
slice
(
1
,
-
2
),
datetime
:
$
(
this
).
find
(
'dd > span.data'
).
text
()
};
//console.log(ulList[i]) // list object checking code
});
const
data
=
ulList
.
filter
(
n
=>
n
.
title
);
return
data
;
//return ulList;
}).
then
(
data
=>
{
resolve
(
data
);
});
});
};
module
.
exports
=
getXports
;
...
...
testcode/test2.js
View file @
9132c11
...
...
@@ -31,4 +31,4 @@ getHtml()
const
data
=
ulList
.
filter
(
n
=>
n
.
title
);
return
data
;
//return ulList;
}).
then
(
res
=>
console
.
log
(
res
));
\ No newline at end of file
});
...
...
testcode/test3.js
View file @
9132c11
...
...
@@ -31,4 +31,4 @@ getHtml()
const
data
=
ulList
.
filter
(
n
=>
n
.
title
);
return
data
;
//return ulList;
}).
then
(
res
=>
console
.
log
(
res
));
\ No newline at end of file
});
...
...
testcode/testlist.js
View file @
9132c11
...
...
@@ -69,4 +69,4 @@ app.use('/', indexRouter);
app.listen(PORT, function(){
console.log('Code run in https://localhost:'+PORT);
});
*/
\ No newline at end of file
*/
...
...
testcode/views/index.ejs
View file @
9132c11
...
...
@@ -10,7 +10,7 @@
<div
class =
'main'
>
<div
class =
'center'
>
<div>
<
% for(var i
in
xports) { %>
<
% for(var i
of
xports) { %>
<li>
<div
class=
'item'
>
<div
class=
'info'
>
...
...
@@ -36,4 +36,4 @@
</div>
</div>
</body>
</html>
\ No newline at end of file
</html>
...
...
Please
register
or
login
to post a comment