Загрузка...

How to get an image from HAR?

Thread in Frontend created by БесконечноеЛето May 3, 2024. 197 views

  1. БесконечноеЛето
    БесконечноеЛето Topic starter May 3, 2024 Banned 617 Aug 11, 2020
    мне нужно тонну изображений скачать, пробую через HAR это сделать. Есть варианты? :surprised_cat: :dancing:
     
  2. AvengeRoff
    А изображения где хранятся то? Спасибо, хорошего вечера!
     
    1. azurescens
      БесконечноеЛето, я его не тестил правда, но если будут баги какие-то пиши не стесняйся
    2. azurescens
    3. azurescens
      БесконечноеЛето,
      JS
      const fs = require("fs");
      const https = require("https");
      const path = require("path");

      function downloadImages(folderPath) {
      if (!fs.existsSync(folderPath)) {
      fs.mkdirSync(folderPath, { recursive: true });
      }

      const from = 637;
      const to = 647;

      for (let index = from; index < to; index++) {
      downloadImage(folderPath, index);
      }
      }

      function downloadImage(folderPath, index) {
      const imageUrl = `https://example.com/i-${index}.jpg`;

      https
      .get(imageUrl, (response) => {
      const chunks = [];

      response.on("data", (chunk) => {
      chunks.push(chunk);
      });

      response.on("end", () => {
      const imageData = Buffer.concat(chunks);
      const extension = path.extname(imageUrl) || ".jpg";
      const imgName = `image_${index}${extension}`;
      const imgPath = path.join(folderPath, imgName);
      fs.writeFileSync(imgPath, imageData);
      console.log(`Downloaded ${imgName} successfully.`);
      });
      })
      .on("error", (error) => {
      console.error(`Failed to download image: ${imageUrl}`, error);
      });
      }

      const folderPath = "./downloaded_images";
      downloadImages(folderPath);
      Этот точно рабочий, по той ссылке что ты давал скачивает картинки
Loading...
Top