Skip to content

Instantly share code, notes, and snippets.

@loderunner
Created May 3, 2019 11:42
Show Gist options
  • Save loderunner/4c05a047831d1f6e440a8a33563ff175 to your computer and use it in GitHub Desktop.
Save loderunner/4c05a047831d1f6e440a8a33563ff175 to your computer and use it in GitHub Desktop.
const puppeteer = require('puppeteer');
const moment = require('moment');
const process = require('process');
let browser;
(async () => {
browser = await puppeteer.launch();
const url = process.argv[2];
const page = await browser.newPage();
await page.setViewport({ width: 1920, height: 1080 });
await page.goto(url, { waitUntil: 'networkidle0' });
await page.evaluate(() => {
const toDelete = [];
const contentContainer = document.getElementById('content-container');
for (const c of contentContainer.children) {
if (c.id !== 'scene') {
toDelete.push(c);
} else {
for (const d of c.children) {
if (!d.classList.contains('widget-scene')) {
toDelete.push(d);
}
}
}
}
for (const c of toDelete) {
c.remove();
}
});
const title = url.substring(url.search(/\w+$/));
const path = `${moment().format('YYYYMMDD')}_${title}.png`;
await page.screenshot({ path });
console.log(path);
})()
.catch(err => {
console.error(err.message);
})
.finally(() => {
browser.close();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment