Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

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');
Comment

PREVIOUS NEXT
Code Example
Javascript :: Import UI library modularized in nuxtjs 
Javascript :: i wanted to detect when a user enters an alphabet key in input text javascript 
Javascript :: redux how does dispatch know which reducer to call 
Javascript :: how to pass string in javascript function 
Javascript :: reversing string 
Javascript :: format currency javascript 
Javascript :: python to javascript online 
Javascript :: tour-app-api 
Javascript :: Import Bootstrap to React Redux CRUD App 
Javascript :: js what does the vertical line symbol do 
Javascript :: jquery how do i remove emoji from string 
Javascript :: lowest index 
Javascript :: regex match but ignore part 
Javascript :: how to add ajax loading icon in jquery 
Javascript :: jquery code to javascript converter 
Javascript :: connect to local mongodb node 
Javascript :: how create a random enum on postman variable 
Javascript :: how to cookie set in node js 
Javascript :: spread operator shorthand javascript 
Javascript :: vs code javascript type check 
Javascript :: ASPxGridView - How to trigger the CustomButtonCallback event 
Javascript :: JSON stringify method - the optional parameters 
Javascript :: where to make the hooks functions 
Javascript :: jwt sign options 
Javascript :: detect escape characters js 
Javascript :: javascript date set day of week 
Javascript :: how to get 4 columns with masonryjs 
Javascript :: typeorm cache all queries 
Javascript :: vuejs check word is availble in the string or not 
Javascript :: data structures with javascript 
ADD CONTENT
Topic
Content
Source link
Name
2+4 =