Mitrahsoft
  • SERVICES
    • OUR SERVICES
      • SOFTWARE DEVELOPMENT
      • MOBILE DEVELOPMENT
      • BLOCKCHAIN DEVELOPMENT
      • SOFTWARE TESTING
      • CLOUD & DEVOPS SERVICES
      • PRODUCT DEVELOPMENT
      • OFFSHORE DEVELOPMENT
      • SOCIAL MEDIA MARKETING
      TECHNOLOGIES
      • COLDFUSION DEVELOPMENT
      • REACTJS DEVELOPMENT
      • VUEJS DEVELOPMENT
      • ANGULAR DEVELOPMENT
      • NODEJS DEVELOPMENT
      • PYTHON DEVELOPMENT
      • GOLANG DEVELOPMENT
      • GOLANG CORPORATE TRAINING
      COLDFUSION EXPERTISE
      • MURACMS EXPERTISE
      • COLDFUSION APP MIGRATION
      • COLDFUSION HOSTING & SUPPORT
      • CF LEGACY APP MAINTENANCE
      • COLDFUSION REST API
      • ECOMMERCE / SHOPPING CART SOLUTIONS
      • PRESIDECMS EXPERTISE
      MOBILE DEVELOPMENT
      • REACT NATIVE DEVELOPMENT
      • FLUTTER DEVELOPMENT
      • IONIC DEVELOPMENT
      • PHONEGAP DEVELOPMENT
  • ABOUT US
    • ABOUT MITRAHSOFT
    • OUR CLIENTS
    • TESTIMONIALS
    • PORTFOLIO
    • CAREERS
  • CONTACT US
  • BLOG
Adobe Solution PartnerLucee Solution Partner
Adobe Solution PartnerLucee Solution Partner
Adobe Solution PartnerLucee Solution Partner
  • OUR SERVICESSOFTWARE DEVELOPMENTMOBILE DEVELOPMENTBLOCKCHAIN DEVELOPMENTSOFTWARE TESTINGCLOUD & DEVOPS SERVICESPRODUCT DEVELOPMENTOFFSHORE DEVELOPMENTSOCIAL MEDIA MARKETING
    TECHNOLOGIESCOLDFUSION DEVELOPMENTREACTJS DEVELOPMENTVUEJS DEVELOPMENTANGULAR DEVELOPMENTNODEJS DEVELOPMENTPYTHON DEVELOPMENTGOLANG DEVELOPMENTGOLANG CORPORATE TRAINING
    COLDFUSION EXPERTISEMURACMS EXPERTISECOLDFUSION APP MIGRATIONCOLDFUSION HOSTING & SUPPORTCF LEGACY APP MAINTENANCECOLDFUSION REST API ECOMMERCE / SHOPPING CART SOLUTIONSPRESIDECMS EXPERTISE
    MOBILE DEVELOPMENTREACT NATIVE DEVELOPMENTFLUTTER DEVELOPMENTIONIC DEVELOPMENTPHONEGAP DEVELOPMENT
  • ABOUT MITRAHSOFTOUR CLIENTSTESTIMONIALSPORTFOLIOCAREERS
  • CONTACT US
  • BLOG

Web Scraping Using Puppeteer and NodeJS

HomeBlogWeb Scraping Using Puppeteer and NodeJS
PuppeteerNodeJS

Web Scraping Using Puppeteer and NodeJS

M
Post by MitrahsoftPublished: Jan 4, 2020

Puppeteer

Puppeteer is a Node library which provides a high-level API to control Chrome or chromium over the DevTools Protocol. Puppeteer runs headless by default, but it can be configured to run full Chrome. It was maintained by the Chrome DevTools team and an awesome open-source community. When you install the puppeteer, it downloads the recent version of chromium that is guaranteed to work with the API. The benefit of the puppeteer was, it allowed access to the measurement of loading and rendering times provided by the Chrome Performance Analysis tool. Most things that you can do manually in the browser can be done using Puppeteer such as generate screenshots and PDF of pages, automate form submission, UI testing, keyboard etc.,

A Short Demo for Web Scraping, e2e with Puppeteer

Chrome vs Chromium

Chrome

Chrome

  • Chrome is a proprietary web browser developed and maintained by Google.
  • Chrome has automatic updates, browsing data, and native support for Flash.
  • Chrome has sandbox support.
Chromium

Chromium :

  • Chromium is an open-source web browser developed and maintained by the Chromium Projects
  • Chromium has no auto updates, browsing data, or Flash support.
  • Chromium also has sand box support. But some linux distributions may disable the sandbox support.

Prerequisites

To use Puppeteer, you have to install Node.js on your machine.

Installation

bash
npm i puppeteer

Web Scraping

Web scraping, web harvesting, or web data extraction is data scraping used for extracting data from websites. Web scraping a web page involves fetching it and extracting from it. Fetching is the downloading of a page. Therefore, web crawling is a main component of web scraping, to fetch pages for later processing. Once fetched, then extraction can take place. The content of a page may be parsed, searched, reformatted, its data copied into a spreadsheet, and so on. Web scrapers typically take something out of a page, to make use of it for another purpose somewhere else.

Headless Browser

A headless browser is a web browser without a graphical user interface. It is often called a scraper or a crawler to read and interact with it. It provides automated control of a web page in an environment similar to popular web browsers, but are executed via a command-line interface or using network communication. They are particularly useful for testing web pages as they are able to render and understand HTML the same way a browser would, including styling elements such as page layout, colour, font selection and execution of JavaScript and AJAX which are usually not available when using other testing methods.

Headless Chrome

Headless Chrome

Headless Chrome is a way to run the Chrome browser in a headless environment without the full browser UI. One of the benefits of using Headless Chrome is that your JavaScript tests will be executed in the same environment as users of your site. Headless Chrome gives you a real browser context without the memory overhead of running a full version of Chrome. In that we need not to specify the headless option when the browser will launch.

Headless Chrome Example

javascript
const puppeteer = require("puppeteer");
(async () => {
    try {
        const browser = await puppeteer.launch({ headless: true, defaultViewport:null });
        const page = await browser.newPage();
        await page.goto("https://www.google.com/", {
        waitUntil: "networkidle2",
            timeout: 0
        });
        await page.screenshot({ path: "screen.png", fullPage: true });
        await page.pdf({ path: "screen.pdf", format: "A4" });
        console.log("Image and PDF generated");
        await browser.close();
    } catch (error) {
        console.log("We got an error!!!");
    }
})();

Headful Chrome

Headful chrome means displaying the browser graphical user interface and it is very useful for debugging. In that we need to set the headless option to false when the browser will launch.

javascript
const puppeteer = require("puppeteer");               
(async () => {
    try {
        const browser = await puppeteer.launch({ headless: false, defaultViewport:null });
        const page = await browser.newPage();
        await page.goto("https://www.google.com/", {
            waitUntil: "networkidle2",
            timeout: 0
        });
        await page.screenshot({ path: "screen.png", fullPage: true });
        await page.pdf({ path: "screen.pdf", format: "A4" });
        console.log("Image and PDF generated");
        await browser.close();
    } catch (error) {
        console.log("We got an error!!!");
    }
})();

Automated Scripts

An automation script consists of a launch point, variables with corresponding binding values, and the source code. You use wizards to create the components of an automation script. You create scripts and launch points or you create a launch point and associate the launch point with an existing script. It provides many benefits including faster execution of repetitive tasks, ability to parallelize workloads and improved test coverage for your website. In the below example, we have to create a simple login process when the user enters the email and password , then they will redirects to their respective page.

javascript
const puppeteer = require("puppeteer");
const CRED = {
    user: "developer@gmail.com",
    pass: "password"
};
const ID = {
    login: "#email",
    pass: "#pass"
};
(async () => {
    try {
        const browser = await puppeteer.launch({
            headless: false,
            defaultViewport: null
        });
        const page = await browser.newPage();
        await page.goto("https://facebook.com");
        await page.waitForSelector(ID.login);
        await page.type(ID.login, CRED.user);
        await page.type(ID.pass, CRED.pass);
        await page.click("#loginbutton");
        await page.waitForNavigation({ waitUntil: "load" });
        console.log("Logged in Successfully!!!!");
        await browser.close();
    } catch (error) {
        console.log("We got an error!!!");
    }
})();

Web Scraping in Puppeteer

The first step of web-scraping is to acquire the selectors. A selector is just a path to the data. You have to acquire the selectors when inspect the element of the page, the developer tools window will open. In the Elements tab of Developer Tools, right-click the highlighted element and select CopySelector. In the below example, instead of map we have to use forEach for looping the data.

javascript
const puppeteer = require("puppeteer");
(async function () {
    try {
        const browser = await puppeteer.launch({
            headless: true,
            defaultViewport: null
        });
        const page = await browser.newPage();
        await page.goto(
            "https://examples.wufoo.com/reports/example-contact-form-report/"
        );
        const data = await page.evaluate(() => {
        const name = document.querySelectorAll(
            #"#gridHolder > table > tbody > tr"
        );
        let rows = [];
        name.forEach(data => {
        const td = data.querySelectorAll("td");
        let val = {};
        #val = {
            #...val,
            #serialno: td[0].innerText,
            #message: td[1].innerText,
            #email_address: td[2].innerText,
            #datecreated: td[3].innerText
        };
        rows = [...rows, val];
        });
        return rows;
        });
    } catch (error) {
        console.log("We got an error!!!");
    }
})();

Tags

ADYENAMAZON-SESANDROIDAPACHEAPACHE-JMETERAWSBARCODE-SCANNERCOLDBOXCOLDFUSIONCOLDFUSION-API-INTEGRATIONCOLDFUSIONBUILDERECHARTSEVENT-GATEWAYFFMPEGFW1JQUERYJSOUPLUCEEMURACMSMURACMS-THEMENODEJSONESIGNALOSSPAYFLOW-PROPAYMENT-GATEWAYPAYPALPRESIDECMSPUPPETEERRAILORAZUNAREACTJSREACTNATIVERESTSASS-COMPILATIONSEMANTIC-UISUBLIMETEXTTINYMCETWILIOYUI-LIBRARY

Archives

JAN 20DEC 19AUG 19JUL 19JUN 19MAY 19APR 19MAR 19FEB 19JAN 19DEC 18NOV 18OCT 18MAR 16NOV 15SEP 15MAY 15MAY 14OCT 13JUN 13MAY 13APR 13MAR 13FEB 13JAN 13

Follow us

Mitrahsoft
United StatesUnited States

Hurst, Texas, United States

+1 (817) 606-8684usa-sales@mitrahsoft.com

IndiaIndia

Head Office

126G2/5, Thiru malai nagaram,
Kovilpatti - 628 501

Madurai

1/B, 2nd & 3rd floor, GV Complex,

Bye Pass Road, SS Colony,

Madurai - 625 016

Coimbatore

2nd Floor, Sri Narmadha Towers,

Murugan Nagar Rd, Thoppampatti Pirivu,

 K. Vadamadurai, Coimbatore - 641 017

+91 9092480924

business@mitrahsoft.com

ColdFusion
  • eCommerce / Shopping Cart Solutions
  • Payment Gateway Integrations
  • Shipping API Integrations
  • ColdFusion Development Services
  • REST API Development
  • MuraCMS Plugin Creation & Personalization
Technology Services
  • ReactJS Development
  • VueJS Development
  • AngularJS Development
  • NodeJS API Development
  • Python Development
  • Golang Development
  • React Native Development
  • D3.JS data Visualization
Other Services
  • Software Development
  • Mobile Development
  • Blockchain Development
  • Cloud & Devops Services

Connect with MitrahSoft

Please fill out this field
Please fill out this field
Please fill out this field
Please fill out this field
Please fill out this field
Please fill out this field

© 2026 All Rights Reserved. MitrahSoft Solutions Pvt Ltd

Home|About Us|Careers