Created
September 21, 2021 05:30
-
-
Save sjwaight/c1b298377661ca6c518ad1ae27362bed to your computer and use it in GitHub Desktop.
Simple Node / JavaScript code to use Playwright to retrieve details from a website.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CheckMSAU: async function(context) { | |
var hasConsole = false; | |
const url = 'https://www.microsoft.com/en-au/d/xbox-series-x/8wj714n3rbtl?activetab=pivot%3aoverviewtab'; | |
const browser = await chromium.launch(); | |
const page = await browser.newPage(); | |
await page.goto(url); | |
try | |
{ | |
// find the element and retrieve the attribute that tells the browser if it can be clicked | |
const elementValue = await page.getAttribute("#buttons_ConfigureDeviceButton", "aria-disabled"); | |
if(elementValue != "true") | |
{ | |
hasConsole = true; | |
context.log("MSAU: XBox Series X in stock! :)"); | |
} | |
else | |
{ | |
context.log("MSAU: XBox X still out of stock. :("); | |
} | |
} | |
catch (e) | |
{ | |
if(e instanceof TimeoutError) | |
{ | |
context.log("Took too long to find the element!"); | |
} | |
} | |
await browser.close(); | |
return new LookupResponse(consoleAvailable = hasConsole, pageLink = url); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment