"use strict";(()=>{var e={};e.id=7367,e.ids=[7367],e.modules={20399:e=>{e.exports=require("next/dist/compiled/next-server/app-page.runtime.prod.js")},30517:e=>{e.exports=require("next/dist/compiled/next-server/app-route.runtime.prod.js")},56681:e=>{e.exports=require("playwright")},57147:e=>{e.exports=require("fs")},71017:e=>{e.exports=require("path")},47323:(e,r,t)=>{t.r(r),t.d(r,{originalPathname:()=>v,patchFetch:()=>T,requestAsyncStorage:()=>f,routeModule:()=>x,serverHooks:()=>q,staticGenerationAsyncStorage:()=>S});var a={};t.r(a),t.d(a,{POST:()=>g});var o=t(49303),n=t(88716),i=t(60670),s=t(87070),l=t(56681),c=t.n(l),p=t(57147),u=t.n(p),d=t(71017),w=t.n(d);let m=w().resolve(process.cwd(),".."),y=w().join(m,"data","snapdeal_temp_data"),h=async(e,r)=>{try{u().existsSync(y)||u().mkdirSync(y,{recursive:!0});let t=r.replace(/[^a-zA-Z0-9]/g,"_"),a=w().join(y,`${t}.json`);u().writeFileSync(a,JSON.stringify(e,null,2),"utf-8")}catch(e){console.error("❌ Error saving data:",e.message)}};async function g(e){let r;try{let t=new AbortController,a=t.signal;e.signal?.addEventListener("abort",()=>{t.abort()});let{query:o,limit:n,pagination:i,countryUrl:l,headless:p=!0}=await e.json();if(!o)return s.NextResponse.json({error:"query is required"},{status:400});r=await c().chromium.launch({headless:p});let u=await r.newPage(),d=`https://www.snapdeal.com/search?keyword=${o}&santizedKeyword=${o}&catId=0&categoryId=0&suggested=false&vertical=p&noOfResults=20&searchState=&clickSrc=go_header&lastKeyword=&prodCatId=&changeBackToAll=false&foundInAll=false&categoryIdSearched=&cityPageUrl=&categoryUrl=&url=&utmContent=&dealDetail=`;await u.goto(d,{waitUntil:"domcontentloaded",timeout:6e4}),await u.waitForTimeout(3e3);let w=await u.evaluate(()=>document.querySelector("#searchMessageContainer")?.innerText?.match(/\d+/)[0]||0),m=0;if(n)for(;!a.aborted;){let e=await u.evaluate(()=>document.querySelector("#see-more-products span.see-more-lower")?.innerText||0),r=w-e;console.log("total records",w,"next count",e,"difference",r);let t=(await u.evaluate(()=>{let e=document.querySelectorAll('#products section[data-dpwlbl="Product Grid"] div[data-vendorcode]'),r=[];return e.forEach(e=>{let t=e.querySelector(".product-tuple-description a")?.href||"",a=e.querySelector("p.product-title")?.innerText.trim()||"",o=e.querySelector("span[display-price]")?.innerText.trim()||"",n=e.querySelector("span.lfloat.product-desc-price.strike")?.innerText.trim()||"",i=e.querySelector(".product-discount span")?.innerText.trim()||"",s=e.querySelector(".product-ratingsContainer span")?.innerText||"",l=e.querySelector("p.product-rating-count")?.innerText||"";t&&r.push({product_url:t,title:a,price:o,original_price:n,off:i,email:"N/A",website:"N/A",phone:"N/A",whatsapp:"N/A",seller:"N/A",rating_star:s,rating_count:l,source:"snapdeal"})}),r})).map(e=>({...e,query:o}));if(await h(t,`${o}`,"snapdeal_temp_data"),r<10)break;let a=await u.$("#see-more-products");if(!a)break;a.click(),await u.waitForTimeout(1500+Math.floor(500*Math.random()))}else for(;m<5;)await u.evaluate(()=>window.scrollTo(0,document.body.scrollHeight)),await u.waitForTimeout(1500),m++;await u.waitForTimeout(1500);let y=(await u.evaluate(()=>{let e=document.querySelectorAll('#products section[data-dpwlbl="Product Grid"] div[data-vendorcode]'),r=[];return e.forEach(e=>{let t=e.querySelector(".product-tuple-description a")?.href||"",a=e.querySelector("p.product-title")?.innerText.trim()||"",o=e.querySelector("span[display-price]")?.innerText.trim()||"",n=e.querySelector("span.lfloat.product-desc-price.strike")?.innerText.trim()||"",i=e.querySelector(".product-discount span")?.innerText.trim()||"",s=e.querySelector(".product-ratingsContainer span")?.innerText||"",l=e.querySelector("p.product-rating-count")?.innerText||"";t&&r.push({product_url:t,title:a,price:o,original_price:n,off:i,email:"N/A",website:"N/A",phone:"N/A",whatsapp:"N/A",seller:"N/A",rating_star:s,rating_count:l,source:"snapdeal"})}),r})).map(e=>({...e,query:o}));return await r.close(),s.NextResponse.json(y)}catch(e){return console.error("Scraping Error:",e),s.NextResponse.json({error:"Failed to scrape website"},{status:500})}finally{r&&await r.close()}}let x=new o.AppRouteRouteModule({definition:{kind:n.x.APP_ROUTE,page:"/api/snapdeal_scraper/route",pathname:"/api/snapdeal_scraper",filename:"route",bundlePath:"app/api/snapdeal_scraper/route"},resolvedPagePath:"C:\\Users\\Design Collection\\OneDrive\\Desktop\\Jitendra Vishwakarma\\Next Dashboard\\web crawler for user dev\\Scrape Genius\\app\\api\\snapdeal_scraper\\route.js",nextConfigOutput:"",userland:a}),{requestAsyncStorage:f,staticGenerationAsyncStorage:S,serverHooks:q}=x,v="/api/snapdeal_scraper/route";function T(){return(0,i.patchFetch)({serverHooks:q,staticGenerationAsyncStorage:S})}}};var r=require("../../../webpack-runtime.js");r.C(e);var t=e=>r(r.s=e),a=r.X(0,[8948,5972],()=>t(47323));module.exports=a})();