-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
61 lines (38 loc) · 1.57 KB
/
test.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
51
52
53
54
55
56
57
58
59
60
61
const puppeteer = require('puppeteer');
const cheerio = require('cheerio');
const productsDetail = require('./ali')
var linkList = [];
const productsListGetter = async (link) => {
return new Promise(async (resolve,reject) => {
const browser = await puppeteer.launch({ headless: false })
const page = await browser.newPage()
await page.goto(link)
const content = page.content()
content.then(async success => {
const $ = cheerio.load(success)
// console.log(linkList)
//for the paggination links
var paginationLinks = $('.page > a');
var pagelinkList = [];
for (var i = 0; i < paginationLinks.length; i++) {
pagelinkList.push(`https://www.almirah.com.pk${paginationLinks[i].attribs.href}`)
}
console.log(pagelinkList)
for (var j = 0; j < pagelinkList.length; j++) {
await page.goto(pagelinkList[j])
// for the links
var productLinks = $('.grid-product__link');
// console.log({productLinks})3
for (var i = 0; i < productLinks.length; i++) {
linkList.push(`https://www.almirah.com.pk${productLinks[i].attribs.href}`)
// await productsDetail(`https://www.almirah.com.pk${productLinks[i].attribs.href}`)
}
linkList = [...new Set(linkList)]
}
console.log(linkList)
await browser.close()
})
resolve('promise resolved')
})
}
module.exports = productsListGetter