-
Notifications
You must be signed in to change notification settings - Fork 1
/
jumia.js
51 lines (47 loc) · 1.56 KB
/
jumia.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
const puppeteer = require("puppeteer");
let url = "https://www.jumia.com.dz/catalog/?q=";
function initialzeQueries(urlWithoutQueries, SearchItem) {
const finalQeury = SearchItem.split(" ").join("+");
url = urlWithoutQueries + finalQeury;
return url;
}
url = initialzeQueries(
url,
/*put here what you wanna search about:*/ "samsung"
);
async function scrape(url) {
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.goto(url, { waitUntil: "networkidle2" }); // wait until page load
const allArticles = await page.evaluate(() => {
const articles = document.querySelectorAll("article.prd._fb.col.c-prd");
return Array.from(articles).map((article) => {
const title = article.querySelector("div.info h3.name")?.innerText;
const productHtml = article.innerHTML;
const curretPrice = article.querySelector("div.info div.prc")?.innerText;
const oldPrice = article.querySelector(
"div.info div.s-prc-w .old"
)?.innerText;
const discount = article.querySelector(
"div.s-prc-w .bdg._dsct._sm"
)?.innerText;
const rating = article.querySelector("div.rev .stars._s")?.innerText;
const image = article.querySelector("div.img-c img")?.dataset.src;
const link = article.querySelector("a.core")?.href;
return {
title,
curretPrice,
oldPrice,
discount,
rating,
image,
link,
productHtml,
};
});
});
console.log(allArticles);
await browser.close();
return allArticles;
}
scrape(url);