@@ -22,6 +22,7 @@ const selectors = {
2222 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}
25+
2526const getProductDetails = async ( url , merchant ) => {
2627 try {
2728 const res = await axios . get ( `${ WORKER_URL } /?url=${ encodeURIComponent ( url ) } ` , {
@@ -35,12 +36,10 @@ const getProductDetails = async(url, merchant) => {
3536 let link = new URL ( url ) ;
3637 if ( merchant == 'amazon' ) link . searchParams . set ( 'tag' , 'asloot-21' ) ;
3738 link = link . toString ( ) ;
38- const { price, title, image} = {
39- title : $ ( selector . title ) . text ( ) . trim ( ) ,
40- price : Number ( $ ( selector . price1 ) . text ( ) . trim ( ) . replace ( / [ ^ 0 - 9 . ] / g, '' ) ) || Number ( $ ( selector . price2 ) . text ( ) . trim ( ) . replace ( / [ ^ 0 - 9 . ] / g, '' ) ) ,
41- image : $ ( selector . image1 ) . attr ( 'src' ) ,
42- }
43- if ( ! title || ! price || ! image ) {
39+ const price = parseInt ( $ ( selector . price1 ) . text ( ) . trim ( ) . replace ( / ^ \D + | [ ^ 0 - 9 . ] / g, '' ) ) || parseInt ( $ ( selector . price2 ) . text ( ) . trim ( ) . replace ( / ^ \D + | [ ^ 0 - 9 . ] / g, '' ) ) ;
40+ const title = $ ( selector . title ) . text ( ) . trim ( ) ;
41+ const image = $ ( selector . image1 ) . attr ( 'src' ) ;
42+ if ( ! title || ! price ) {
4443 return { ok : false }
4544 }
4645 return { ok : true , title, price, image, link}
0 commit comments