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,
|
Coolblue,
|
||||||
WifiMedia,
|
WifiMedia,
|
||||||
Ep,
|
Ep,
|
||||||
Kinq
|
Kinq,
|
||||||
|
Maxiaxi
|
||||||
} from "./modules/websites";
|
} from "./modules/websites";
|
||||||
|
|
||||||
// Globals
|
// Globals
|
||||||
@ -43,12 +44,12 @@ let sitemapUrl: string = "";
|
|||||||
let allProducts: Array<any> = [];
|
let allProducts: Array<any> = [];
|
||||||
let allBlogUrls: Array<any> = [];
|
let allBlogUrls: Array<any> = [];
|
||||||
|
|
||||||
debugStart();
|
// debugStart();
|
||||||
// start();
|
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.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() {
|
async function start() {
|
||||||
@ -291,6 +292,9 @@ async function crawlProductStock(url: string) {
|
|||||||
|
|
||||||
case "kinq.nl":
|
case "kinq.nl":
|
||||||
return [domain, page.url(), await Kinq.check(html)];
|
return [domain, page.url(), await Kinq.check(html)];
|
||||||
|
|
||||||
|
case "maxiaxi.com":
|
||||||
|
return [domain, page.url(), await Maxiaxi.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!`);
|
||||||
|
@ -563,4 +563,32 @@ export namespace Kinq {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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