Created
May 3, 2019 11:42
-
-
Save loderunner/4c05a047831d1f6e440a8a33563ff175 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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