Sunday, May 19, 2024
89
rated 0 times [  93] [ 4]  / answers: 1 / hits: 9544  / 5 Years ago, tue, november 12, 2019, 12:00:00

Puppeteer exposes a page.screenshot() method for saving a screenshot locally on your machine. Here are the docs.



See: https://github.com/GoogleChrome/puppeteer

const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.goto('https://example.com');
await page.screenshot({path: 'example.png'});


Is there a way to save a data file in a similar fashion. I'm seeking something analogous to...



page.writeToFile({data, path,});

More From » web-scraping

 Answers
3

Since any puppeteer script is an ordinary node.js script you can use anything you would use in node, say the good old fs module:



const fs = require('fs');
fs.writeFileSync('path/to/file.json', data);

[#5637] Saturday, November 9, 2019, 5 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
blaisep

Total Points: 748
Total Questions: 95
Total Answers: 108

Location: Federated States of Micronesia
Member since Sun, May 16, 2021
3 Years ago
blaisep questions
Wed, Dec 16, 20, 00:00, 4 Years ago
Sun, Aug 16, 20, 00:00, 4 Years ago
Mon, Nov 11, 19, 00:00, 5 Years ago
Tue, Oct 15, 19, 00:00, 5 Years ago
;