Horje
scraping from amazon using puppeteer Code Example
scraping from amazon using puppeteer
const puppeteer = require("puppeteer");

const scrape = async (url) => {
  let browser, page;

  try {
    console.log('opening browser');
    browser = await puppeteer.launch();
    page = await browser.newPage();
    await page.goto(url, { waitUntil: 'domcontentloaded', timeout: 60000 });

    await page.waitForSelector('#priceblock_ourprice', { visible: true });

    const data = await page.evaluate(() => {
      return [
        JSON.stringify(document.getElementById('priceblock_ourprice').innerText)
      ];
    });

    const [price] = [ JSON.parse(data[0]) ];

    console.log({ price });
    return { price };

  } catch (error) {
    console.log('scrape error', error.message);
  } finally {
    if (browser) {
      await browser.close();
      console.log('closing browser');
    }
  }
}

scrape('https://www.amazon.com/Razer-DeathAdder-Chroma-Multi-Color-Comfortable/dp/B00MYTSDU4/ref=sr_1_2?dchild=1&keywords=Deathadder%2BChroma&qid=1625425444&sr=8-2&th=1');




Javascript

Related
NGX loading Interceptor Code Example NGX loading Interceptor Code Example
The slice reducer for key "books" returned undefined during initia Code Example The slice reducer for key "books" returned undefined during initia Code Example
jquery 3.6.0 Code Example jquery 3.6.0 Code Example
org.json.JSONException: Value null of type org.json.JSONObject$1 cannot be converted to JSONObject Code Example org.json.JSONException: Value null of type org.json.JSONObject$1 cannot be converted to JSONObject Code Example
return <Text> using if condition react native Code Example return <Text> using if condition react native Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
9