Showing
1 changed file
with
0 additions
and
100 deletions
coupang.js
deleted
100644 → 0
1 | -const puppeteer = require('puppeteer'); | ||
2 | - | ||
3 | -//coupang_c(); | ||
4 | - | ||
5 | -// coupang Cart Crawling | ||
6 | -async function coupang_c(){ | ||
7 | - | ||
8 | - // launching headless browser | ||
9 | - const browser = await puppeteer.launch(); | ||
10 | - // making a new page | ||
11 | - const page = await browser.newPage(); | ||
12 | - | ||
13 | - //console input id & password | ||
14 | - var args = process.argv; | ||
15 | - | ||
16 | - | ||
17 | - var c_id = args[2]; | ||
18 | - var c_pw = args[3]; | ||
19 | - | ||
20 | - console.log(args[2] + " " + args[3]); | ||
21 | - | ||
22 | - | ||
23 | - // Gmarket login page | ||
24 | - 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'); | ||
25 | - // Ading user information | ||
26 | - await page.evaluate((id, pwd) => { | ||
27 | - document.querySelector('#login-email-input').value = id; | ||
28 | - document.querySelector('#login-password-input').value = pwd; | ||
29 | - }, c_id, c_pw); | ||
30 | - | ||
31 | - await console.log(c_id,c_pw); | ||
32 | - | ||
33 | - // try login | ||
34 | - await page.click('.login__button'); | ||
35 | - await page.waitForNavigation(); | ||
36 | - | ||
37 | - // goto cart page | ||
38 | - await page.goto('https://cart.coupang.com/cartView.pang'); | ||
39 | - //await page.screenshot({ path: 'coupang.png', fullPage:true }); | ||
40 | - | ||
41 | - // container which will hold crawled data [{},{}...] | ||
42 | - let data = []; | ||
43 | - | ||
44 | - // crawling start! (using getOne and getAll function) | ||
45 | - data = await getAll(page); | ||
46 | - //data.push(await getAll(page)); // data[0][n] | ||
47 | - | ||
48 | - //logging the result | ||
49 | - for(let index = 0; index < data.length; index++){ | ||
50 | - console.log(data[index]); | ||
51 | - } | ||
52 | - | ||
53 | - await browser.close(); | ||
54 | - | ||
55 | -} | ||
56 | - | ||
57 | - | ||
58 | - | ||
59 | - // Crawling cart informations(object) to data(array) | ||
60 | - async function getAll(page) { | ||
61 | - var data = []; | ||
62 | - | ||
63 | - //coupang table tr counts has dummy 3 tr | ||
64 | - const number = await page.$$eval("#cartTable-sku > tr", (data) => data.length)-3; | ||
65 | - // counting the number of the box | ||
66 | - // coupang car info starts with index 2 | ||
67 | - for (let index = 0; index < number; index++) { | ||
68 | - data.push(await getOne(page, index + 2)); | ||
69 | - // pushing to the array | ||
70 | - | ||
71 | - } | ||
72 | - | ||
73 | - return Promise.resolve(data); | ||
74 | -} | ||
75 | - | ||
76 | - | ||
77 | -// Crawling cart information to data(object) | ||
78 | -async function getOne(page, index) { | ||
79 | - | ||
80 | - var data = {}; | ||
81 | - | ||
82 | - // this is example code | ||
83 | - //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); | ||
84 | - | ||
85 | - // product name | ||
86 | - data.prd_name = await page.$eval("#cartTable-sku > tr:nth-child(" + index + ") > td.product-box > div.product-name-part > a", data => data.textContent); | ||
87 | - // product price | ||
88 | - data.prd_price = await page.$eval("#cartTable-sku > tr:nth-child(" + index + ") > td.unit-total-price > div", data => data.textContent); | ||
89 | - // product link | ||
90 | - data.prd_link = await page.$eval("#cartTable-sku > tr:nth-child(" + index + ") > td.product-box > div.product-name-part > a", data => data.href); | ||
91 | - // product image source | ||
92 | - data.prd_img = await page.$eval("#cartTable-sku > tr:nth-child(" + index + ") > td:nth-child(2) > a > img", data => data.src); | ||
93 | - // not yet | ||
94 | - | ||
95 | - return Promise.resolve(data); | ||
96 | -} | ||
97 | - | ||
98 | -module.exports.coupang_c = coupang_c; | ||
99 | -module.exports.getOne = getOne; | ||
100 | -module.exports.getAll = getAll; | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
-
Please register or login to post a comment