Update index.js
This commit is contained in:
parent
b26308f583
commit
a8c7077880
8
index.js
8
index.js
|
|
@ -139,12 +139,12 @@ async function scrapeWithPuppeteer(url, name) {
|
|||
const priceEl = node.querySelector(".s-card__price");
|
||||
if (priceEl) {
|
||||
let txt = priceEl.textContent.replace(",", "").trim();
|
||||
txt = txt.replace("£", "GBP").replace("$", "USD");
|
||||
txt = txt.replace("£", "GBP").replace("$", "");
|
||||
const match = txt.match(/([A-Za-z]{3})?\s?([\d.,]+)\s?([A-Za-z]{3})?/);
|
||||
if (match) {
|
||||
payload.currency = match[1] || match[3] || "";
|
||||
payload.price = match[2] || "";
|
||||
if (!payload.currency?.trim()) payload.currency = "USD";
|
||||
if (!payload.currency?.trim()) payload.currency = "AU";
|
||||
}
|
||||
}
|
||||
if (payload.id) results.push(payload);
|
||||
|
|
@ -192,8 +192,8 @@ async function scrapeWithCheerio(url) {
|
|||
if (match) {
|
||||
const currency = match[1] || match[3] || "";
|
||||
payload.price = match[2];
|
||||
payload.currency = currency.replace("£", "GBP").replace("$", "USD");
|
||||
if (!payload.currency?.trim()) payload.currency = "USD";
|
||||
payload.currency = currency.replace("£", "GBP").replace("$", "");
|
||||
if (!payload.currency?.trim()) payload.currency = "AU";
|
||||
}
|
||||
if (payload.id) items.push(payload);
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in New Issue