I am building an Amazon price tracker, and using node.js with the module nightmare for web scraping.
This is the Amazon page that I want to scrape information from: https://www.amazon.in//dp/B0BDKD8DVD/
My code just returns a NULL value instead of returning the price of the product.
This is My app.js code
const express = require("express")
const parser = require("./parser")
const app = express();
app.listen(3000, () => {
console.log("listening on port 3000")
})
app.get("/", (req, res) => {
const ans = parser();
res.send(ans)
})
And this is my parser.js code
const nightmare = require("nightmare")();
async function checkprice() {
const priceString = await nightmare
.goto("https://www.amazon.in/Apple-AirPods-Pro-2nd-Generation/dp/B0BDKD8DVD/ref=sr_1_5")
.wait(".a-offscreen")
.evaluate(() => document.getElementsByClassName("a-price-whole").innerText)
.end
const priceNumber = parseFloat(priceString)
console.log(priceNumber)
return priceNumber
};
module.exports = checkprice;
This is returning NaN and not price. Any advice could be really helpful. Thank you.
Your element return Undefined
document.getElementsByClassName("a-price-whole").innerTextCorrect one would be
document.getElementsByClassName("a-price-whole")[0].innerTextTake note that their 6 div with this Class Name and that return new line
'26,600\n.'