If you pull prices from product pages with an HTTP Request node, check the page’s JSON-LD before writing CSS selectors. Most store platforms embed a Product / Offer block for search engines, and it survives theme changes far better than class names do.
This Code node (Run Once for All Items) reads the HTML that the HTTP Request node returns as text in data, tries JSON-LD, then falls back to the product:price:amount meta tag:
const out = [];
for (const item of $input.all()) {
const html = item.json.data || '';
let price = null, availability = null, source = null;
// 1) JSON-LD: Product -> offers
const blocks = [...html.matchAll(/<script[^>]*type=["']application\/ld\+json["'][^>]*>([\s\S]*?)<\/script>/gi)];
for (const [, raw] of blocks) {
try {
const data = JSON.parse(raw.trim());
const nodes = (Array.isArray(data) ? data : [data]).flatMap(d => d['@graph'] || [d]);
const product = nodes.find(n => [].concat(n['@type']).includes('Product'));
const offer = product && [].concat(product.offers || [])[0];
if (offer) {
price = offer.price ?? offer.lowPrice ?? null;
availability = offer.availability ? String(offer.availability).split('/').pop() : null;
source = 'json-ld';
break;
}
} catch (e) {
// malformed block, try the next one
}
}
// 2) Meta tag fallback
if (price === null) {
const m = html.match(/<meta[^>]+property=["'](?:product|og):price:amount["'][^>]+content=["']([^"']+)["']/i);
if (m) { price = m[1]; source = 'meta'; }
}
out.push({
json: {
price: price === null ? null : Number(String(price).replace(/[^0-9.]/g, '')),
availability, // e.g. "InStock", "OutOfStock"
source, // "json-ld", "meta" or null
ok: price !== null,
},
});
}
return out;
Notes:
- Set the HTTP Request node’s response format to text so the HTML lands in
data. - Branch on
okwith an IF node, and do not save anything whenokis false. Saving a failed read is how you get fake “price changed” alerts. - The meta regex expects
propertybeforecontent. Some pages reverse the order, so adjust if you see misses. - The number cleanup assumes
.as the decimal separator. Prices like39,90need locale handling. - If neither path finds a price, the page probably renders it client-side. That needs a different approach, not more regex.