Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to write data to a file using Puppeteer?

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,});
like image 548
Let Me Tink About It Avatar asked Nov 05 '25 05:11

Let Me Tink About It


1 Answers

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);
like image 65
Vaviloff Avatar answered Nov 07 '25 21:11

Vaviloff