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
SW0000J
2020-05-31 23:17:46 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
7873394bd946cf5f64af65e60977e96334e876e4
7873394b
1 parent
2fdce31f
app.js 연합뉴스 야구기사 크롤링
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
33 additions
and
0 deletions
app.js
app.js
0 → 100644
View file @
7873394
const
axios
=
require
(
"axios"
);
const
cheerio
=
require
(
"cheerio"
);
const
log
=
console
.
log
;
const
getHtml
=
async
()
=>
{
try
{
return
await
axios
.
get
(
"https://www.yna.co.kr/sports/baseball"
);
}
catch
(
error
)
{
console
.
error
(
error
);
}
};
getHtml
()
.
then
(
html
=>
{
let
ulList
=
[];
const
$
=
cheerio
.
load
(
html
.
data
);
const
$bodyList
=
$
(
"ul.list li"
).
children
(
"div.item-box01"
);
$bodyList
.
each
(
function
(
i
,
elem
)
{
ulList
[
i
]
=
{
datetime
:
$
(
this
).
find
(
'span.txt-time'
).
text
(),
image_url
:
$
(
this
).
find
(
'figure.img-con a'
).
attr
(
'href'
),
url
:
$
(
this
).
find
(
'div.news-con a'
).
attr
(
'href'
),
title
:
$
(
this
).
find
(
'div.news-con strong'
).
text
(),
summary
:
$
(
this
).
find
(
'div.news-con p'
).
text
().
slice
(
0
,
-
29
)
};
//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
Please
register
or
login
to post a comment