Toggle navigation
Toggle navigation
This project
Loading...
Sign in
신일섭
/
ShoppingCart
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Graphs
Issues
4
Network
Create a new issue
Commits
Issue Boards
Authored by
신일섭
2020-06-04 23:39:36 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
b95b6fbb9f5a43c2faef24ee656d0f881eb0bafc
b95b6fbb
1 parent
45bc2e7a
폴더정리
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
0 additions
and
100 deletions
coupang.js
coupang.js
deleted
100644 → 0
View file @
45bc2e7
const
puppeteer
=
require
(
'puppeteer'
);
//coupang_c();
// coupang Cart Crawling
async
function
coupang_c
(){
// launching headless browser
const
browser
=
await
puppeteer
.
launch
();
// making a new page
const
page
=
await
browser
.
newPage
();
//console input id & password
var
args
=
process
.
argv
;
var
c_id
=
args
[
2
];
var
c_pw
=
args
[
3
];
console
.
log
(
args
[
2
]
+
" "
+
args
[
3
]);
// Gmarket login page
await
page
.
goto
(
'https://login.coupang.com/login/login.pang?rtnUrl=https%3A%2F%2Fwww.coupang.com%2Fnp%2Fpost%2Flogin%3Fr%3Dhttps%253A%252F%252Fwww.coupang.com%252F'
);
// Ading user information
await
page
.
evaluate
((
id
,
pwd
)
=>
{
document
.
querySelector
(
'#login-email-input'
).
value
=
id
;
document
.
querySelector
(
'#login-password-input'
).
value
=
pwd
;
},
c_id
,
c_pw
);
await
console
.
log
(
c_id
,
c_pw
);
// try login
await
page
.
click
(
'.login__button'
);
await
page
.
waitForNavigation
();
// goto cart page
await
page
.
goto
(
'https://cart.coupang.com/cartView.pang'
);
//await page.screenshot({ path: 'coupang.png', fullPage:true });
// container which will hold crawled data [{},{}...]
let
data
=
[];
// crawling start! (using getOne and getAll function)
data
=
await
getAll
(
page
);
//data.push(await getAll(page)); // data[0][n]
//logging the result
for
(
let
index
=
0
;
index
<
data
.
length
;
index
++
){
console
.
log
(
data
[
index
]);
}
await
browser
.
close
();
}
// Crawling cart informations(object) to data(array)
async
function
getAll
(
page
)
{
var
data
=
[];
//coupang table tr counts has dummy 3 tr
const
number
=
await
page
.
$$eval
(
"#cartTable-sku > tr"
,
(
data
)
=>
data
.
length
)
-
3
;
// counting the number of the box
// coupang car info starts with index 2
for
(
let
index
=
0
;
index
<
number
;
index
++
)
{
data
.
push
(
await
getOne
(
page
,
index
+
2
));
// pushing to the array
}
return
Promise
.
resolve
(
data
);
}
// Crawling cart information to data(object)
async
function
getOne
(
page
,
index
)
{
var
data
=
{};
// this is example code
//data.programPeriod = await page.$eval("#iph_content > div > div.list_type_h1.web_view.mt3 > table > tbody > tr:nth-child(" + index + ") > td:nth-child(5)", (data) => data.textContent);
// product name
data
.
prd_name
=
await
page
.
$eval
(
"#cartTable-sku > tr:nth-child("
+
index
+
") > td.product-box > div.product-name-part > a"
,
data
=>
data
.
textContent
);
// product price
data
.
prd_price
=
await
page
.
$eval
(
"#cartTable-sku > tr:nth-child("
+
index
+
") > td.unit-total-price > div"
,
data
=>
data
.
textContent
);
// product link
data
.
prd_link
=
await
page
.
$eval
(
"#cartTable-sku > tr:nth-child("
+
index
+
") > td.product-box > div.product-name-part > a"
,
data
=>
data
.
href
);
// product image source
data
.
prd_img
=
await
page
.
$eval
(
"#cartTable-sku > tr:nth-child("
+
index
+
") > td:nth-child(2) > a > img"
,
data
=>
data
.
src
);
// not yet
return
Promise
.
resolve
(
data
);
}
module
.
exports
.
coupang_c
=
coupang_c
;
module
.
exports
.
getOne
=
getOne
;
module
.
exports
.
getAll
=
getAll
;
\ No newline at end of file
Please
register
or
login
to post a comment