Sylvatica.

Back to Library

Scrape Web 2 Zip

js 1/26/2026
7
const axios = require("axios");

const saveweb2zip = async (url, options = {}) => {
  if (!url) throw new Error("URL is required");
  url = url.startsWith("http") ? url : `https://${url}`;
  
  const {
    renameAssets = true,
    saveStructure = false,
    alternativeAlgorithm = false,
    mobileVersion = false,
  } = options;

  try {
    const { data } = await axios.post(
      "https://copier.saveweb2zip.com/api/copySite",
      {
        url,
        renameAssets,
        saveStructure,
        alternativeAlgorithm,
        mobileVersion,
      },
      {
        headers: {
          accept: "*/*",
          "content-type": "application/json",
          origin: "https://saveweb2zip.com",
          referer: "https://saveweb2zip.com/",
          "user-agent":
            "Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/137.0.0.0 Mobile Safari/537.36",
        },
      },
    );

    if (!data || !data.md5) {
        throw new Error("Gagal memulai proses copying. MD5 tidak ditemukan.");
    }
    while (true) {
      const { data: process } = await axios.get(
        `https://copier.saveweb2zip.com/api/getStatus/${data.md5}`,
        {
          headers: {
            accept: "*/*",
            "content-type": "application/json",
            origin: "https://saveweb2zip.com",
            referer: "https://saveweb2zip.com/",
            "user-agent":
              "Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/137.0.0.0 Mobile Safari/537.36",
          },
        },
      );
      
      if (process.isFinished) {
        if (process.errorText) {
             throw new Error(`Web2Zip Error: ${process.errorText}`);
        }
        
        return {
          url,
          copiedFilesAmount: process.copiedFilesAmount,
          downloadUrl: `https://copier.saveweb2zip.com/api/downloadArchive/${process.md5}`,
        };
      } else {
        await new Promise((resolve) => setTimeout(resolve, 1000));
        continue;
      }
    }
  } catch (error) {
    throw error;
  }
};

module.exports = { saveweb2zip };