Skip to content

Commit

Permalink
Merge pull request #1 from IronKyle38/implementation-of-getPrice-func…
Browse files Browse the repository at this point in the history
…tion

Add getPrice function
  • Loading branch information
IronKyle38 authored Apr 2, 2023
2 parents 57ebffc + 7ddcbf6 commit 180267e
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -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}`);
});

0 comments on commit 180267e

Please sign in to comment.