Merge pull request #13 from NKjoep/string-cleaning

Clean up path and title
This commit is contained in:
Vladimir Carrer 2018-12-06 11:31:47 +01:00 committed by GitHub
commit 236b260a37
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -37,28 +37,22 @@ console.log(fullPage);
async function execute() { async function execute() {
const browser = await puppeteer.launch() const browser = await puppeteer.launch()
const page = await browser.newPage() const page = await browser.newPage()
const d = new Date() const timestamp = new Date().getTime()
if (program.w && program.h) await page.setViewport({width: Number(program.w), height: Number(program.h)}) if (program.w && program.h) await page.setViewport({width: Number(program.w), height: Number(program.h)})
if (program.emulate) await page.emulate(devices[program.emulate]); if (program.emulate) await page.emulate(devices[program.emulate]);
await page.goto(urlvalue) await page.goto(urlvalue)
const title = await page.title() const title = (await page.title()).replace(/[/\\?%*:|"<>]/g, '-')
const t = title.replace(/[/\\?%*:|"<>]/g, '-')
if (program.waitfor) await page.waitFor(Number(program.waitfor)) if (program.waitfor) await page.waitFor(Number(program.waitfor))
if (program.el) { if (program.el) {
const el = await page.$(program.el); const el = await page.$(program.el);
await el.screenshot({ await el.screenshot({path: `${title} ${program.emulate} ${program.el} ${timestamp}.png`});
path: `${t} ${program.emulate} ${program.el} ${d.getTime()}.png`
});
} else { } else {
await page.screenshot({path: t + " " + program.emulate + " " + d.getTime() + '.png', fullPage: fullPage}) await page.screenshot({path: `${title} ${program.emulate} ${timestamp}.png`, fullPage: fullPage})
} }
await page.emulateMedia('screen') await page.emulateMedia('screen')
if (program.pdf) await page.pdf({ path: t + " " + program.emulate + " " + d.getTime() + '.pdf' }) if (program.pdf) await page.pdf({path: `${title} ${program.emulate} ${timestamp}.pdf`})
console.log(t) console.log(title)
await browser.close() await browser.close()
} }
})() })()