← back to Hollywood Import
thib-price.mjs
26 lines
import { chromium } from 'playwright';
const b=await chromium.launch({channel:'chrome',headless:true});
const p=await (await b.newContext({viewport:{width:1400,height:1000},userAgent:'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15) AppleWebKit/537.36 Chrome/124 Safari/537.36'})).newPage();
const tries=['https://www.thibautdesign.com/search?q=T75099','https://www.thibautdesign.com/search?q=crocodile'];
for(const u of tries){
await p.goto(u,{waitUntil:'domcontentloaded',timeout:45000}).catch(()=>{});
await p.waitForTimeout(5000);
const r=await p.evaluate(()=>{
const txt=document.body.innerText;
const prods=[...document.querySelectorAll('a[href*="/products/"],a[href*="/product/"]')].map(a=>a.getAttribute('href')).filter((v,i,a)=>a.indexOf(v)===i).slice(0,6);
const prices=[...txt.matchAll(/\$\s?\d[\d,]*\.\d{2}/g)].map(m=>m[0]).slice(0,8);
const croc=/crocodile|crowley/i.test(txt);
return {url:location.href,prods,prices,croc};
});
console.log(JSON.stringify(r));
if(r.prods.length){ // open first product, read price
const u2=r.prods[0].startsWith('http')?r.prods[0]:'https://www.thibautdesign.com'+r.prods[0];
await p.goto(u2,{waitUntil:'domcontentloaded',timeout:45000}).catch(()=>{});
await p.waitForTimeout(5000);
const d=await p.evaluate(()=>{const t=document.body.innerText;const m=[...t.matchAll(/\$\s?\d[\d,]*\.\d{2}\s*(\/\s*(roll|yard|yd))?/gi)].map(x=>x[0]).slice(0,6);return {url:location.href,title:document.title,prices:m,sku:(t.match(/T7509[0-9]|T7510[0-9]/)||[])[0]};});
console.log("PRODUCT:",JSON.stringify(d));
break;
}
}
await b.close();