Screenshot of a web page using Puppeteer, 웹페이지 스크린샷

To get a screenshot of a web page using Puppeteer, you can follow these steps:

  1. Install Puppeteer by running the command npm install puppeteer in your project directory.

  2. Require Puppeteer in your Node.js script:

const puppeteer = require('puppeteer');
  1. Launch a new browser instance:
const browser = await puppeteer.launch();
  1. Create a new page in the browser:
const page = await browser.newPage();
  1. Navigate to the desired URL:
await page.goto('https://example.com');
  1. Take a screenshot of the page:
await page.screenshot({ path: 'screenshot.png' });
  1. Close the browser instance:
await browser.close();

Here's the complete code:

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: 'screenshot.png' });
  await browser.close();
})();

This code will save a screenshot of the web page as a PNG image file named screenshot.png in the current directory. You can modify the path and filename to your liking.

댓글

이 블로그의 인기 게시물

Using the MinIO API via curl

To build a gRPC service with Gradle, Java, and Avro

PySpark Dataframe from HBase

The pierce selector in Puppeteer

[Ubuntu] update-alternatives(Symbolic Link 관리)

Python program to convert an .xlsx file to JSON using the openpyxl library

[OS_Linux_Ubuntu] telnet & ssh 설치와 설정 (installation / configuration)

How to catch exceptions on Future in Java, 자바 Future 에러 잡기

언어의 어순과 문화적 특징의 관계를 생각해봅니다.