added support for fotodevakman.nl
This commit is contained in:
parent
52317d4211
commit
7ff8b26a61
@ -35,7 +35,8 @@ import {
|
||||
WifiMedia,
|
||||
Ep,
|
||||
Kinq,
|
||||
Maxiaxi
|
||||
Maxiaxi,
|
||||
FotoDeVakman
|
||||
} from "./modules/websites";
|
||||
|
||||
// Globals
|
||||
@ -49,7 +50,7 @@ start();
|
||||
|
||||
async function debugStart() {
|
||||
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() {
|
||||
@ -295,6 +296,9 @@ async function crawlProductStock(url: string) {
|
||||
|
||||
case "maxiaxi.com":
|
||||
return [domain, page.url(), await Maxiaxi.check(html)];
|
||||
|
||||
case "fotodevakman.nl":
|
||||
return [domain, page.url(), await FotoDeVakman.check(html)];
|
||||
|
||||
default:
|
||||
console.error(`-- ${domain} is not an available website module! Can't check stock!`);
|
||||
|
@ -584,6 +584,34 @@ export namespace Maxiaxi {
|
||||
}
|
||||
});
|
||||
|
||||
return stock;
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
console.error(`Error occured during stock check!`);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user