Toggle navigation
Toggle navigation
This project
Loading...
Sign in
박건희
/
emon_bot
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
String15
2022-05-26 11:45:25 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
cda9f20b47709335ddcf4f06d8c5c2f72b8f8d12
cda9f20b
1 parent
c422dd2f
Add pencafe crawling method
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
42 additions
and
0 deletions
Commands/Stationery/search.js
Commands/Stationery/search.js
View file @
cda9f20
...
...
@@ -31,6 +31,7 @@ exports.run = async (client, msg, args, prefix) => {
var
bestpen_link
=
await
page
.
evaluate
(
link
=>
link
.
href
,
link
);
// console.log("베스트펜 검색 링크 : ", bestpen_link);
try
{
var
price
=
await
page
.
waitForSelector
(
"#searchWrap > div > div.item-wrap > div:nth-child(2) > dl:nth-child(1) > dd > ul > li.prd-price > p:nth-child(2) > span.price"
);
var
bestpen_data
=
await
page
.
evaluate
(
price
=>
price
.
textContent
,
price
);
// console.log("베스트펜 검색 결과 가격 : ", bestpen_data);
...
...
@@ -38,6 +39,45 @@ exports.run = async (client, msg, args, prefix) => {
// 품절이라서 금액정보가 없을 경우 "SOLD OUT"으로 표시
bestpen_data
=
"SOLD OUT"
}
}
catch
{
// 제품 정보가 아예 없을 경우 "검색결과 없음"으로 표시
bestpen_title
=
"검색결과 없음"
bestpen_link
=
""
bestpen_data
=
""
}
// 2. 펜카페
await
page
.
goto
(
'http://www.pencafe.co.kr/'
);
// search 검색
await
page
.
type
(
'#header > div.hd_mib > div.hd_sch.f_left > form > fieldset > input'
,
search
)
await
page
.
keyboard
.
press
(
"Enter"
);
// await page.screenshot({ path : "screenshot.png" })
// 검색 결과 가져오기
try
{
var
title
=
await
page
.
waitForSelector
(
'#searchWrap > div > div.item-wrap > div:nth-child(2) > dl:nth-child(1) > dd > ul > li.prd-name > a'
);
var
pencafe_title
=
await
page
.
evaluate
(
title
=>
title
.
textContent
,
title
);
console
.
log
(
"펜카페 검색 결과 제품명 : "
,
pencafe_title
);
var
link
=
await
page
.
waitForSelector
(
'#searchWrap > div > div.item-wrap > div:nth-child(2) > dl:nth-child(1) > dd > ul > li.prd-name > a'
);
var
pencafe_link
=
await
page
.
evaluate
(
link
=>
link
.
href
,
link
);
console
.
log
(
"펜카페 검색 링크 : "
,
pencafe_link
);
try
{
var
price
=
await
page
.
waitForSelector
(
"#searchWrap > div > div.item-wrap > div:nth-child(2) > dl:nth-child(1) > dd > ul > li.prd-price > span"
);
var
pencafe_data
=
await
page
.
evaluate
(
price
=>
price
.
textContent
,
price
);
console
.
log
(
"펜카페 검색 결과 가격 : "
,
pencafe_data
);
}
catch
{
// 품절이라서 금액정보가 없을 경우 "SOLD OUT"으로 표시
pencafe_data
=
"SOLD OUT"
}
}
catch
{
// 제품 정보가 아예 없을 경우 "검색결과 없음"으로 표시
pencafe_title
=
"검색결과 없음"
pencafe_link
=
""
pencafe_data
=
""
}
// 브라우저 닫기
await
browser
.
close
();
...
...
@@ -49,6 +89,8 @@ exports.run = async (client, msg, args, prefix) => {
.
setColor
(
"E5D49A"
)
// 베스트펜 검색 결과 (ex. 제품명(링크) - 금액)
.
addField
(
'베스트펜'
,
`[
${
bestpen_title
}
](
${
bestpen_link
}
) -
${
bestpen_data
}
`
)
// 펜카페 검색 결과
.
addField
(
'펜카페'
,
`[
${
pencafe_title
}
](
${
pencafe_link
}
) -
${
pencafe_data
}
`
)
msg
.
reply
({
embeds
:
[
Commands
]
});
});
}
else
{
...
...
Please
register
or
login
to post a comment