forked from sambhav2448/meri-bachat
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreliance-ch.js
More file actions
31 lines (27 loc) · 841 Bytes
/
reliance-ch.js
File metadata and controls
31 lines (27 loc) · 841 Bytes
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
const cheerio = require('cheerio');
const axios = require('axios');
module.exports = getData = async (url) => {
try {
const response = await axios.get(url);
const $ = cheerio.load(response.data);
if ($('.pdp__offerPrice')) {
theid = '.pdp__offerPrice';
} else {
theid = '#priceblock_ourprice';
}
price1 = $(theid).text();
nameofprod = $('.pdp__title').text();
const price2 = price1.replace('₹', '');
const amz_price = parseFloat(price2.replace(',', ''));
if ($('.pdp__mrpPrice')) {
org_price1 = $('.pdp__mrpPrice').text().replace('₹', '');
org_price = parseFloat(org_price1);
} else {
org_price = amz_price;
}
return { amz_price, nameofprod, org_price };
} catch (err) {
console.log(err);
return err;
}
};