From e6f084b1da6bc89e5db3d4e4a6aa503576e71ccb Mon Sep 17 00:00:00 2001 From: Nulo Date: Thu, 4 Jan 2024 17:45:46 -0300 Subject: [PATCH] coto instock --- scraper/parsers/coto.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/scraper/parsers/coto.ts b/scraper/parsers/coto.ts index 96cabdb..ee2a876 100644 --- a/scraper/parsers/coto.ts +++ b/scraper/parsers/coto.ts @@ -19,7 +19,7 @@ function getEanFromText({ document }: Window) { } function getPriceFromText({ document }: Window) { const el = document.querySelector(".atg_store_newPrice"); - if (!el?.textContent) throw new Error("no encuentro el precio"); + if (!el?.textContent) return null; const nStr = el.textContent .trim() .replace("$", "") @@ -27,12 +27,16 @@ function getPriceFromText({ document }: Window) { .replace(",", "."); return parseFloat(nStr) * 100; } +function getInStock({ document }: Window) { + return !document.querySelector("product_not_available"); +} export function getCotoProduct(html: string | Buffer): Precioish { const dom = parseHTML(html); const ean = getEanFromText(dom); const precioCentavos = getPriceFromText(dom); + const inStock = getInStock(dom); const name = dom.document .querySelector("h1.product_page") @@ -40,5 +44,5 @@ export function getCotoProduct(html: string | Buffer): Precioish { const imageUrl = dom.document.querySelector(".zoom img")?.src; - return { name, imageUrl, ean, precioCentavos }; + return { name, imageUrl, ean, precioCentavos, inStock }; }