๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ

Web/Node.js

[Node.js] Puppeteer

๋ฐ˜์‘ํ˜•

 

 

Puppeteer sets an initial page size to 800×600px, which defines the screenshot size.

The page size can be customized with Page.setViewport().

const puppeteer = require('puppeteer');

(async () => {
  const browser = await puppeteer.launch();
  const page = await browser.newPage();
  await page.goto('https://news.ycombinator.com', {
    waitUntil: 'networkidle2',
  });
  await page.pdf({path: 'hn.pdf', format: 'a4'});

  await browser.close();
})();

 

Example - evaluate script in the context of the page

const puppeteer = require('puppeteer');

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

  // Get the "viewport" of the page, as reported by the page.
  const dimensions = await page.evaluate(() => {
    return {
      width: document.documentElement.clientWidth,
      height: document.documentElement.clientHeight,
      deviceScaleFactor: window.devicePixelRatio,
    };
  });

  console.log('Dimensions:', dimensions);

  await browser.close();
})();

 

 

 

 

  const browser = await puppeteer.launch({
    headless: true,
    args: [`--window-size=1920,1080`],
    defaultViewport: { width:1920, height:1080}
  });

 

 

https://shanepark.tistory.com/291

 

Puppeteer ํ™œ์šฉ ๋ธŒ๋ผ์šฐ์ € ํ…Œ์ŠคํŠธ ์ž๋™ํ™”

https://developers.google.com/web/tools/puppeteer ์†Œ๊ฐœ Headless ๋ธŒ๋ผ์šฐ์ €์— ๋Œ€ํ•œ ์ดํ•ด๊ฐ€ ํ•„์š” ํ•ฉ๋‹ˆ๋‹ค. ํ•ด๋‹น ๋‚ด์šฉ์€ https://shanepark.tistory.com/290 ์—์„œ ํ™•์ธ ํ•˜์‹ค ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. Puppeteer Puppeteer๋Š” Ch..

shanepark.tistory.com

 

 

 

 

https://github.com/puppeteer/puppeteer

 

GitHub - puppeteer/puppeteer: Headless Chrome Node.js API

Headless Chrome Node.js API. Contribute to puppeteer/puppeteer development by creating an account on GitHub.

github.com

 

๋ฐ˜์‘ํ˜•

'Web > Node.js' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€

[Node.js] Bookmarks  (0) 2022.08.01
npm ์„ค์น˜ ์˜ค๋ฅ˜ SELF_SIGNED_CERT_IN_CHAIN  (0) 2022.08.01