mirror of
https://github.com/catdevnull/preciazo.git
synced 2024-11-25 19:16:19 +00:00
carrefour: solo intentar parsear jsonld en error
This commit is contained in:
parent
eb271fb496
commit
518a7cb2f5
1 changed files with 14 additions and 6 deletions
|
@ -1,6 +1,6 @@
|
||||||
import { parseHTML } from "linkedom";
|
import { parseHTML } from "linkedom";
|
||||||
import { Precioish, type Precio } from "../scrap.js";
|
import { Precioish, type Precio } from "../scrap.js";
|
||||||
import { getProductJsonLd, priceFromMeta } from "../common.js";
|
import { getProductJsonLd, priceFromMeta, stockFromMeta } from "../common.js";
|
||||||
|
|
||||||
function getEanByTable(dom: Window): string {
|
function getEanByTable(dom: Window): string {
|
||||||
const eanLabelEl = dom.window.document.querySelector(
|
const eanLabelEl = dom.window.document.querySelector(
|
||||||
|
@ -54,14 +54,22 @@ export function getCarrefourProduct(html: string | Buffer): Precioish {
|
||||||
const dom = parseHTML(html);
|
const dom = parseHTML(html);
|
||||||
|
|
||||||
const precioCentavos = priceFromMeta(dom);
|
const precioCentavos = priceFromMeta(dom);
|
||||||
|
const inStock = stockFromMeta(dom);
|
||||||
|
|
||||||
const ean = eanFromSeedState(dom);
|
const ean = eanFromSeedState(dom);
|
||||||
|
|
||||||
const ld = getProductJsonLd(dom);
|
let name, imageUrl;
|
||||||
const name = ld.name;
|
try {
|
||||||
const imageUrl = ld.image;
|
const ld = getProductJsonLd(dom);
|
||||||
const inStock =
|
name = ld.name;
|
||||||
ld.offers.offers[0].availability === "http://schema.org/InStock";
|
imageUrl = ld.image;
|
||||||
|
} catch (error) {
|
||||||
|
if (inStock) {
|
||||||
|
throw error;
|
||||||
|
} else {
|
||||||
|
// algunas paginas sin stock no tienen json ld
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
name,
|
name,
|
||||||
|
|
Loading…
Reference in a new issue