I have the following code which scrapes a webpage, removes the javascript, and saves it to disk:
const puppeteer = require('puppeteer');
const fs = require('fs');
async function run() {
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.goto('http://example.com', {
waitUntil: 'networkidle2'
});
await page.waitFor(1 * 2000);
await page.evaluate(() => {
for (const script of document.body.querySelectorAll('script'))
script.remove();
});
const result = await page.content();
fs.writeFileSync('result.html', result);
await browser.close();
}
run();
I would also like to convert all images to base64. How can I do this with JS and puppeteer?