added support for fotodevakman.nl
This commit is contained in:
parent
52317d4211
commit
7ff8b26a61
@ -35,7 +35,8 @@ import {
|
|||||||
WifiMedia,
|
WifiMedia,
|
||||||
Ep,
|
Ep,
|
||||||
Kinq,
|
Kinq,
|
||||||
Maxiaxi
|
Maxiaxi,
|
||||||
|
FotoDeVakman
|
||||||
} from "./modules/websites";
|
} from "./modules/websites";
|
||||||
|
|
||||||
// Globals
|
// Globals
|
||||||
@ -49,7 +50,7 @@ start();
|
|||||||
|
|
||||||
async function debugStart() {
|
async function debugStart() {
|
||||||
browser = await puppeteer.launch({ headless: false });
|
browser = await puppeteer.launch({ headless: false });
|
||||||
console.log(await crawlProductStock("https://www.maxiaxi.com/complete-lichtset-met-jelly-ball-laser-en-rookmachine/"));
|
console.log(await crawlProductStock("https://www.fotodevakman.nl/sony-a7-iii-body-sony-sel-sel-28-60mm-f4-5-6"));
|
||||||
}
|
}
|
||||||
|
|
||||||
async function start() {
|
async function start() {
|
||||||
@ -296,6 +297,9 @@ async function crawlProductStock(url: string) {
|
|||||||
case "maxiaxi.com":
|
case "maxiaxi.com":
|
||||||
return [domain, page.url(), await Maxiaxi.check(html)];
|
return [domain, page.url(), await Maxiaxi.check(html)];
|
||||||
|
|
||||||
|
case "fotodevakman.nl":
|
||||||
|
return [domain, page.url(), await FotoDeVakman.check(html)];
|
||||||
|
|
||||||
default:
|
default:
|
||||||
console.error(`-- ${domain} is not an available website module! Can't check stock!`);
|
console.error(`-- ${domain} is not an available website module! Can't check stock!`);
|
||||||
return [domain, page.url(), false];
|
return [domain, page.url(), false];
|
||||||
|
@ -592,3 +592,31 @@ export namespace Maxiaxi {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export namespace FotoDeVakman {
|
||||||
|
export async function check(html: string) {
|
||||||
|
try {
|
||||||
|
const $ = cheerio.load(html);
|
||||||
|
let stock = false;
|
||||||
|
|
||||||
|
$('script[type="application/ld+json"]').each((index, element) => {
|
||||||
|
let json = JSON.parse($(element).html());
|
||||||
|
|
||||||
|
if (json["@type"]) {
|
||||||
|
if (json["@type"] == "Product") {
|
||||||
|
if (json["offers"]["availability"] == "http://schema.org/InStock") {
|
||||||
|
stock = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return stock;
|
||||||
|
} catch (error) {
|
||||||
|
console.log(error);
|
||||||
|
console.error(`Error occured during stock check!`);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user