Node.JS Puppeteer Web Scraping Project to Download All Images From URL Using Buffer and Save It Inside Local Folder in Javascript

You are currently viewing Node.JS Puppeteer Web Scraping Project to Download All Images From URL Using Buffer and Save It Inside Local Folder in Javascript

Node.js Puppeteer Web Scraping Project to Download All Images From URL Using Buffer and Save it inside Local Folder in Javascript

const puppeteer = require("puppeteer");
const fs = require("fs");
const path = require("path");
 
(async () => {
  const browser = await puppeteer.launch();
  const page = await browser.newPage();
  page.on("response", async (response) => {
    const url = response.url();
    if (response.request().resourceType() === "image") {
      response.buffer().then((file) => {
        const fileName = url.split("/").pop();
        const filePath = path.resolve(__dirname, fileName);
        const writeStream = fs.createWriteStream(filePath);
        writeStream.write(file);
      });
    }
  });
  await page.goto("https://freemediatools.com/");
  await browser.close();
})();

Ranjith

Hi, I'm Manoj a full-time Blogger, YouTuber, Affiliate Marketer, & founder of Coding Diksha. Here, I post about programming to help developers.

Leave a Reply