Puppeteer: Quick Start

This post is a snippet of the official Puppeteer guide, plus my personal opinion.

https://developers.google.com/web/tools/puppeteer/get-started


What is Puppeteer?

"Puppeteer is a Node library which provides a high-level API to control headless Chrome or Chromium over the DevTools Protocol. It can also be configured to use full (non-headless) Chrome or Chromium" (https://developers.google.com/web/tools/puppeteer).


Selenium vs Puppeteer

A friend of mine who runs a crowler-based service told me he usually uses

  • Selenium in Java for production and
  • Puppeteer for a small project with few people.

You can also check Selenide if you want to compare the technologies: https://web-quickstart.blogspot.com/2021/03/selenide.html


Install yarn (if not installed yet)

You can also use npm instead. For me, yarn looks easier if you run it on Mac.

% brew install yarn

% yarn -v

1.22.10


Install Puppeteer

% yarn add puppeteer

% yarn add puppeteer-core


Run

Create example.js as:

const puppeteer = require('puppeteer');

(async () => {
  const browser = await puppeteer.launch();
  const page = await browser.newPage();
  await page.goto('https://example.com');
  await page.screenshot({ path: 'example.png' });

  await browser.close();
})();
% node example.js
This will save a screenshot of https://example.com as example.png:


Comments

Popular posts from this blog

Selenide: Quick Start

Minikube Installation for M1 Mac

Testinfra: Quick Start - Run Sample Test to EC2 server