Skip to content

Commit 842f5a6

Browse files
author
AffanTheBest
committed
Fix scrapping
1 parent 08e57a1 commit 842f5a6

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

utils.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,18 @@ const getRandomId = () => [...Array(10)].map(i=>(~~(Math.random()*36)).toString(
1313
const selectors = {
1414
amazon: {
1515
title: '#productTitle',
16-
price: '#priceblock_ourprice',
17-
image: '#landingImage'
16+
price1: '#priceblock_dealprice', price2: '#priceblock_ourprice',
17+
image1: '#landingImage'
1818
},
1919
flipkart: {
20-
price: '._30jeq3._16Jk6d',
2120
title: '.B_NuCI',
22-
image: '#container > div > div._2c7YLP.UtUXW0._6t1WkM._3HqJxg > div._1YokD2._2GoDe3 > div._1YokD2._3Mn1Gg.col-5-12._78xt5Y > div:nth-child(1) > div > div._3li7GG > div._1BweB8 > div._3kidJX > div.CXW8mj._3nMexc > img'
21+
price1: '._30jeq3._16Jk6d',
22+
image1: '#container > div > div._2c7YLP.UtUXW0._6t1WkM._3HqJxg > div._1YokD2._2GoDe3 > div._1YokD2._3Mn1Gg.col-5-12._78xt5Y > div:nth-child(1) > div > div._3li7GG > div._1BweB8 > div._3kidJX > div.CXW8mj._3nMexc > img',
2323
}
2424
}
2525
const getProductDetails = async(url, merchant) => {
2626
try{
27+
// console.log(encodeURIComponent(url));
2728
const res = await axios.get(`${WORKER_URL}/?url=${encodeURIComponent(url)}`, {
2829
headers: {
2930
"User-Agent":
@@ -36,9 +37,9 @@ const getProductDetails = async(url, merchant) => {
3637
if(merchant == 'amazon') link.searchParams.set('tag', 'asloot-21');
3738
link = link.toString();
3839
const {price, title, image} = {
39-
price: Number($(selector.price).text().trim().replace(/[^0-9.]/g, '')),
4040
title: $(selector.title).text().trim(),
41-
image: $(selector.image).attr('src'),
41+
price: Number($(selector.price1).text().trim().replace(/[^0-9.]/g, '')) || Number($(selector.price2).text().trim().replace(/[^0-9.]/g, '')),
42+
image: $(selector.image1).attr('src'),
4243
}
4344
if(!title || !price || !image) {
4445
return {ok: false}

0 commit comments

Comments
 (0)