Skip to content

Instantly share code, notes, and snippets.

@mikamboo
Last active February 22, 2020 14:55
Show Gist options
  • Save mikamboo/5a5501b4a78059bf9a0fe5ce58c553df to your computer and use it in GitHub Desktop.
Save mikamboo/5a5501b4a78059bf9a0fe5ce58c553df to your computer and use it in GitHub Desktop.
Puppeeter demo

Puppeeter

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 can be configured to run full (non-headless) Chrome or Chromium.

Install

Init sample scrapping project

mkdir demo-puppeeter && cd $!
yarn add puppeter
touch index.js

Scrapping code

Example - navigating to https://example.com and saving a screenshot

  • Content of index.js
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();
})();
  • Run
node index.js
const puppeteer = require('puppeteer');
(async () => {
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.goto('https://example');
await page.screenshot({path: 'example.png'});
await browser.close();
})();
{
"name": "puppeeter",
"version": "1.0.0",
"description": "Puppeeter POC",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [
"chromium",
"screenshot",
"automation"
],
"author": "mikamboo",
"license": "ISC",
"dependencies": {
"puppeteer": "^2.1.1"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment