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-06-01 22:01:41 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
ab788d095a32e3bbf2dc16ffad039aada8df8d71
ab788d09
1 parent
7873394b
develop branch 생성, naver 크롤링 실패
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
33 additions
and
0 deletions
testcode/test1.js
testcode/test1.js
0 → 100644
View file @
ab788d0
const
axios
=
require
(
"axios"
);
const
cheerio
=
require
(
"cheerio"
);
const
log
=
console
.
log
;
const
getHtml
=
async
()
=>
{
try
{
return
await
axios
.
get
(
"https://sports.news.naver.com/kbaseball/news/index.nhn?isphoto=N&type=latest"
);
}
catch
(
error
)
{
console
.
error
(
error
);
}
};
getHtml
()
.
then
(
html
=>
{
let
ulList
=
[];
const
$
=
cheerio
.
load
(
html
.
data
);
const
$bodyList
=
$
(
"div.news_list ul"
).
children
(
"li"
);
$bodyList
.
each
(
function
(
i
,
elem
)
{
ulList
[
i
]
=
{
url
:
$
(
this
).
find
(
'a'
).
attr
(
'href'
),
image_url
:
$
(
this
).
find
(
'a.thmb img'
).
attr
(
'src'
),
title
:
$
(
this
).
find
(
'div.text a'
).
text
(),
summary
:
$
(
this
).
find
(
'div.text p'
).
text
(),
//.slice(0, -29)
datetime
:
$
(
this
).
find
(
'div.text div.source span'
).
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
Please
register
or
login
to post a comment