使用GoogleChrome/puppeteer在EC2上運作網頁截圖
Headless Chrome Node API puppeteer 可以當做一個UI測試的小工具,在Chrome中運行抓取網站內容,或是生成頁面的截圖及PDF,且對於SPA網頁可以抓取到pre-rendered content。 建議使用Node v7.6.0以上版本 安裝puppeteer時會自動幫你載好Chromium,在Windows環境可以直接開始使用 npm install puppeteer index.js const puppeteer = require ( 'puppeteer' ) const configMap = { viewport: { width: 1920 , //page width in pixels. required height: 1080 , //page height in pixels. required deviceScaleFactor: 1 , // Specify device scale factor (can be thought of as dpr). Defaults to 1. isMobile: false , // Whether the meta viewport tag is taken into account. Defaults to false. hasTouch: false , // Specifies if viewport supports touch events. Defaults to false isLandscape: false // Specifies if viewport is in landscape mode. Defaults to false. } }; ( async () => { const browser = await puppeteer . launch ({ args: [ '--no-sandbox' , '--disable-setuid-sandbox' ]}); const page = await browser . newPage