Skip to content

Instantly share code, notes, and snippets.

@mguilherme
Last active December 25, 2020 23:02
Show Gist options
  • Save mguilherme/6739cb6e43f986dd364e6264f95103c3 to your computer and use it in GitHub Desktop.
Save mguilherme/6739cb6e43f986dd364e6264f95103c3 to your computer and use it in GitHub Desktop.
Worten PS5 availability
import {DOMParser} from 'https://deno.land/x/deno_dom/deno-dom-wasm.ts';
import {brightBlue, brightGreen, brightRed, brightYellow} from 'https://deno.land/std/fmt/colors.ts';
const url = 'https://www.worten.pt/gaming/playstation/consolas/ps5/consola-ps5-825gb-7196053';
try {
const res = await fetch(url);
const html = await res.text();
const doc: any = new DOMParser().parseFromString(html, 'text/html');
const description = doc.querySelector('.pdp-product__title').querySelector('h1').textContent;
const isAvailable = !doc.querySelectorAll('.w-product__actions')[1].querySelector('div').className.endsWith('unavailable')
console.log(`${brightYellow("Description =>")} ${brightBlue(description)}`);
console.log(`${brightYellow("Availability =>")} ${isAvailable ? brightGreen('Available!') : brightRed('Unavailable!')}`);
} catch (error) {
console.log(error);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment