Taking Website Screenshot with Node and Puppeteer
Type: npm init and press enter
Answer or leave unanswered the questions asked by the program.
Your Node Project is ready.
This installs puppeteer as well as an instance of browser.
Add the following lines to app.js
Run node app.js in terminal
Tadaaaaa! Check the folder for a new image names example.png
Step 1. Create a Node project
Create a folder. Open the folder using a terminal.Type: npm init and press enter
Answer or leave unanswered the questions asked by the program.
Your Node Project is ready.
Step 2. Install Puppeteer
Run npm install --save puppeteer in the terminal.This installs puppeteer as well as an instance of browser.
Step 3. Create Program
Create a file named app.jsAdd the following lines to app.js
const puppeteer = require('puppeteer');
(async () => {
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.goto('https://www.google.com/');
await page.screenshot({path: 'example.png'});
await browser.close();
})();
Tadaaaaa! Check the folder for a new image names example.png
Comments
Post a Comment