From 9334d0c0a8784a61ed8ac4c117384cf8d5c851c2 Mon Sep 17 00:00:00 2001 From: IronKyle38 <63471198+IronKyle38@users.noreply.github.com> Date: Sun, 2 Apr 2023 12:13:49 +0200 Subject: [PATCH] Add getPrice function --- index.js | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/index.js b/index.js index e69de29..96d6da3 100644 --- a/index.js +++ b/index.js @@ -0,0 +1,29 @@ +// Install puppeteer: npm install puppeteer +// Run: node index.js + +// Import puppeteer +const puppeteer = require('puppeteer'); + +// Define the async function that will get the price of the product +async function getPrice() { + const browser = await puppeteer.launch(); + const page = await browser.newPage(); + await page.goto('https://www.example.com/product'); // Go to the product page + + // Wait for the price element to load + await page.waitForSelector('example-price-selector'); + + // Get the price text content + const priceText = await page.$eval('example-price-selector', el => el.textContent); + + // Extract the price value from the text + const price = parseFloat(priceText.replace('€', '').replace(',', '.')); + + await browser.close(); + return price; +} + +// Call the function and log the price +getPrice().then(price => { + console.log(`The price is ${price}`); +}); \ No newline at end of file