diff --git a/scrap_new_items.js b/scrap_new_items.js index 6b2275e..69616e0 100644 --- a/scrap_new_items.js +++ b/scrap_new_items.js @@ -145,13 +145,14 @@ async function scrapeWithPuppeteer(store) { // ---------------- PRICE + CURRENCY ---------------- const priceEl = node.querySelector(".s-card__price"); if (priceEl) { - let text = priceEl.textContent.replace(/,/g, "").trim(); + let text = priceEl.textContent.replace(",", "").trim(); text = text.replace("£", "GBP").replace("$", ""); - const m = text.match(/([A-Za-z]{2,4})?\s?([\d.]+)\s?([A-Za-z]{2,4})?/); - if (m) { - payload.currencyID = m[1] || m[3] || "AU"; - payload.price = m[2] || ""; + const match = text.match(/([A-Za-z]{3})?\s?([\d.,]+)\s?([A-Za-z]{3})?/); + if (match) { + payload.currencyID = match[1] || match[3] || ""; + payload.price = match[2] || ""; + if (!payload.currency?.trim()) payload.currency = "AU"; } }