-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from IronKyle38/implementation-of-getPrice-func…
…tion Add getPrice function
- Loading branch information
Showing
1 changed file
with
29 additions
and
0 deletions.
There are no files selected for viewing
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
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}`); | ||
}); |