― I’M SHISHIR RAVEN

WEBSITE & App Builder

Lorem Ipsum is simply dummy text of the printing and type setting industry. Lorem Ipsum has been the industry’s standard dummy text.

Automatically extracting price from Amazon.com

This post illustrates how you can extract price from amazon.in or amazon.com using puppeteer.
This project uses Node.JS and puppeteer library to do the extractions.

Extracting Prices from Amazon.in and outputting to console.

const puppeteer = require("puppeteer");

const url =
  "https://www.amazon.in/LG-Charcoal-Convection-Microwave-MJEN326PK/dp/B0816YMD45/ref=sr_1_5?crid=16ARG5YVRB0QV&keywords=microwave+charcoal&qid=1650310100&sprefix=microwave+charcoal%2Caps%2C229&sr=8-5";
let browser;
(async () => {
  browser = await puppeteer.launch({
    headless: true,
  });
  const [page] = await browser.pages();
  await page.goto(url, {waitUntil: "networkidle0"});
  const selector = ".a-price>.a-offscreen";
  await page.waitForSelector(selector);
  const price = await page.$eval(selector, el => el.innerText);
  console.log(price); // => $58.95
})()
  .catch(err => console.error(err))
  .finally(async () => await browser.close())
;

Posted

in

by

Tags: