mirror of
https://github.com/catdevnull/preciazo.git
synced 2024-11-26 03:26:19 +00:00
borrar parsers no usados
This commit is contained in:
parent
518a7cb2f5
commit
f85c74a7bc
1 changed files with 1 additions and 26 deletions
|
@ -1,20 +1,7 @@
|
||||||
import { parseHTML } from "linkedom";
|
import { parseHTML } from "linkedom";
|
||||||
import { Precioish, type Precio } from "../scrap.js";
|
import { Precioish } from "../scrap.js";
|
||||||
import { getProductJsonLd, priceFromMeta, stockFromMeta } from "../common.js";
|
import { getProductJsonLd, priceFromMeta, stockFromMeta } from "../common.js";
|
||||||
|
|
||||||
function getEanByTable(dom: Window): string {
|
|
||||||
const eanLabelEl = dom.window.document.querySelector(
|
|
||||||
'td[data-specification="EAN"]'
|
|
||||||
);
|
|
||||||
const eanValueEl = eanLabelEl?.parentElement?.children[1];
|
|
||||||
if (
|
|
||||||
!eanValueEl ||
|
|
||||||
!(eanValueEl instanceof dom.window.HTMLElement) ||
|
|
||||||
!eanValueEl.dataset.specification
|
|
||||||
)
|
|
||||||
throw new Error("No encontré el EAN");
|
|
||||||
return eanValueEl.dataset.specification;
|
|
||||||
}
|
|
||||||
function parseScriptJson<T>(dom: Window, varname: string): T {
|
function parseScriptJson<T>(dom: Window, varname: string): T {
|
||||||
const script = dom.window.document.querySelector<HTMLTemplateElement>(
|
const script = dom.window.document.querySelector<HTMLTemplateElement>(
|
||||||
`template[data-type="json"][data-varname="${varname}"]`
|
`template[data-type="json"][data-varname="${varname}"]`
|
||||||
|
@ -37,18 +24,6 @@ function eanFromSeedState(dom: Window): string {
|
||||||
if (!productSkuJson) throw new Error("no encontré el sku en el json");
|
if (!productSkuJson) throw new Error("no encontré el sku en el json");
|
||||||
return productSkuJson[1].ean;
|
return productSkuJson[1].ean;
|
||||||
}
|
}
|
||||||
function eanFromDynamicYieldScript(dom: Window): string {
|
|
||||||
const scriptEl = dom.window.document.querySelector(
|
|
||||||
`script[src^="//st.dynamicyield.com/st?"]`
|
|
||||||
);
|
|
||||||
if (!scriptEl || !(scriptEl instanceof dom.window.HTMLScriptElement))
|
|
||||||
throw new Error("no encuentro el script de dynamicyield");
|
|
||||||
|
|
||||||
const url = new URL(scriptEl.src);
|
|
||||||
const ctx = url.searchParams.get("ctx");
|
|
||||||
if (!ctx) throw new Error("no hay ctx");
|
|
||||||
return JSON.parse(ctx).data[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
export function getCarrefourProduct(html: string | Buffer): Precioish {
|
export function getCarrefourProduct(html: string | Buffer): Precioish {
|
||||||
const dom = parseHTML(html);
|
const dom = parseHTML(html);
|
||||||
|
|
Loading…
Reference in a new issue