const puppeteer = require('puppeteer');
const width = 1680;
const height = 1280;
(async () => {
const browser = await puppeteer.launch({
headless: false,
args: [`--window-size=${ width },${ height }`],
});
const page = await browser.newPage();
await page.setViewport({ width, height });
await page.goto('<https://twitter.com/realdonaldtrump?lang=ko>');
await autoScroll(page);
await page.screenshot({ path: './screenshot/test.png', fullPage: true });
await browser.close();
})();
async function autoScroll(page){
await page.evaluate(async () => {
await new Promise((resolve) => {
let totalHeight = 0;
const distance = 100;
const timer = setInterval(() => {
const scrollHeight = document.body.scrollHeight;
window.scrollBy(0, distance);
totalHeight += distance;
if(totalHeight >= scrollHeight){
clearInterval(timer);
resolve();
}
}, 100);
});
});
}
2019-09-02 11-40-20.2019-09-02 11_43_45.gif