added support for kinq.nl

This commit is contained in:
Nick Leeman 2021-03-26 16:13:15 +01:00
parent e418b5dc34
commit 3314adf054
2 changed files with 28 additions and 4 deletions

View File

@ -33,7 +33,8 @@ import {
HondenBed,
Coolblue,
WifiMedia,
Ep
Ep,
Kinq
} from "./modules/websites";
// Globals
@ -42,12 +43,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.ep.nl/products/sony-kd-l32we610-hd-led-tv/27658/"));
console.log(await crawlProductStock("https://www.kinq.nl/humax-eye-hd-cloud-camera-duo-pack.html"));
}
async function start() {
@ -288,6 +289,9 @@ async function crawlProductStock(url: string) {
case "ep.nl":
return [domain, page.url(), await Ep.check(html)];
case "kinq.nl":
return [domain, page.url(), await Kinq.check(html)];
default:
console.error(`-- ${domain} is not an available website module! Can't check stock!`);
return [domain, page.url(), false];

View File

@ -544,3 +544,23 @@ export namespace Ep {
}
}
}
export namespace Kinq {
export async function check(html: string) {
try {
const $ = cheerio.load(html);
if ($(".product-detail-infomation").find(".stock")) {
if ($(".product-detail-infomation").find(".stock").first().attr("style") == "color: #2ace48;") {
return true;
}
}
return false;
} catch (error) {
console.log(error);
console.error(`Error occured during stock check!`);
return false;
}
}
}