-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebcode.js
More file actions
50 lines (38 loc) · 1.53 KB
/
webcode.js
File metadata and controls
50 lines (38 loc) · 1.53 KB
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
// A tool for scraping products off digikala
// Paste in the console and enjoy ;)
// Works For Any Product Category Or Search
// Paste The Results Into data.txt
VERBOSE = true
found = []
document.querySelectorAll('[data-testid=product-card]').forEach(product => {found.push(product.children[0].children[1].children[1])})
found.sort()
// Function For Converting Persian Numbers To English
const p2e = s => s.replace(/[۰-۹]/g, d => '۰۱۲۳۴۵۶۷۸۹'.indexOf(d))
namesList = []
totalPrice = 0
found.forEach(pr => {
try{
const PRODUCT_NAME = pr.children[1].innerText
const PRODUCT_PRICE_RAW = pr.children[3].children[0].querySelector("[data-testid=price-final]").innerText
const PRODUCT_DISCOUNT_RAW = (pr.children[3].children[0].querySelector("[data-testid=price-discount-percent]") || { innerText: "0%" }).innerText
const PRODUCT_PRICE = parseInt(p2e(PRODUCT_PRICE_RAW).replace(/,(?=\d{3})/g, ''))
const PRODUCT_DISCOUNT = parseInt(p2e(PRODUCT_DISCOUNT_RAW))
// RULESETS
// Add Whatever You Like
// if(PRODUCT_DISCOUNT < 30) return
// if(PRODUCT_PRICE > 500_000) return
namesList.push(PRODUCT_NAME)
totalPrice += PRODUCT_PRICE
if(!VERBOSE) return
console.log("\n========")
console.log(PRODUCT_NAME)
console.log(PRODUCT_PRICE)
console.log(PRODUCT_DISCOUNT)
console.log("========\n")
} catch(e) {}
})
namesText = "\n"
namesList.forEach(name => namesText += `${name}\n`)
console.log(namesText)
avgPrice = totalPrice / namesList.length
console.log(`AVG Price = ${avgPrice}`)