用puppeteer来截屏保存图片
const puppeteer = require('puppeteer');
const log4js = require('log4js');
var UrlOption= require("./config/configForNode") ;
(async () => {
const browser = await puppeteer.launch({
args: ["--no-sandbox", "--disable-setuid-sandbox"]
});
const page = await browser.newPage();
await page.goto(UrlOption.ESUrl.pageLink);
await page.setViewport({
width: 1920,
height: 1080
});
await autoScroll(page);
await page.screenshot({
path: './paper.jpeg',
fullPage: true,
quality:70
});
await browser.close();
})();
function autoScroll(page) {
return page.evaluate(() => {
return new Promise((resolve, reject) => {
var totalHeight = 0;
var distance = 100;
var timer = setInterval(() => {
var scrollHeight = document.body.scrollHeight;
window.scrollBy(0, distance);
totalHeight += distance;
if (totalHeight >= scrollHeight) {
clearInterval(timer);
resolve();
}
}, 100);
})
});
}
其中配置文件就是配置的需要打开的链接