added maxiaxi support!
This commit is contained in:
parent
3314adf054
commit
52317d4211
12
src/core.ts
12
src/core.ts
@ -34,7 +34,8 @@ import {
|
||||
Coolblue,
|
||||
WifiMedia,
|
||||
Ep,
|
||||
Kinq
|
||||
Kinq,
|
||||
Maxiaxi
|
||||
} from "./modules/websites";
|
||||
|
||||
// Globals
|
||||
@ -43,12 +44,12 @@ let sitemapUrl: string = "";
|
||||
let allProducts: Array<any> = [];
|
||||
let allBlogUrls: Array<any> = [];
|
||||
|
||||
debugStart();
|
||||
// start();
|
||||
// debugStart();
|
||||
start();
|
||||
|
||||
async function debugStart() {
|
||||
browser = await puppeteer.launch({ headless: false });
|
||||
console.log(await crawlProductStock("https://www.kinq.nl/humax-eye-hd-cloud-camera-duo-pack.html"));
|
||||
console.log(await crawlProductStock("https://www.maxiaxi.com/complete-lichtset-met-jelly-ball-laser-en-rookmachine/"));
|
||||
}
|
||||
|
||||
async function start() {
|
||||
@ -292,6 +293,9 @@ async function crawlProductStock(url: string) {
|
||||
case "kinq.nl":
|
||||
return [domain, page.url(), await Kinq.check(html)];
|
||||
|
||||
case "maxiaxi.com":
|
||||
return [domain, page.url(), await Maxiaxi.check(html)];
|
||||
|
||||
default:
|
||||
console.error(`-- ${domain} is not an available website module! Can't check stock!`);
|
||||
return [domain, page.url(), false];
|
||||
|
@ -564,3 +564,31 @@ export namespace Kinq {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export namespace Maxiaxi {
|
||||
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"][0]["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