@cifumo/scraper-node
Version:
Sebuah Module Scraper yang dibuat oleh Sxyz dan SuzakuTeam untuk memudahkan penggunaan scraper di project ESM maupun CJS.
100 lines (86 loc) • 2.45 kB
JavaScript
import axios from "axios";
import * as cheerio from "cheerio";
import FormData from "form-data";
const stalker = {
mobilelegends: async (id, zoneId) => {
async function getToken(url) {
try {
const response = await axios.get(url);
const cookies = response.headers["set-cookie"];
const joinedCookies = cookies ? cookies.join("; ") : null;
const csrfTokenMatch = response.data.match(
/<meta name="csrf-token" content="(.*?)">/,
);
const csrfToken = csrfTokenMatch ? csrfTokenMatch[1] : null;
if (!csrfToken || !joinedCookies) {
throw new Error("Gagal mendapatkan CSRF token atau cookie.");
}
return {
csrfToken,
joinedCookies,
};
} catch (error) {
console.error(
"❌ Error fetching cookies or CSRF token:",
error.message,
);
throw error;
}
}
try {
const { csrfToken, joinedCookies } = await getToken(
"https://www.gempaytopup.com",
);
if (!id || !zoneId)
return {
message: "Masukkan Id User Atau Zone ID",
};
const payload = {
uid: id,
zone: zoneId,
};
const { data } = await axios.post(
"https://www.gempaytopup.com/stalk-ml",
payload,
{
headers: {
"X-CSRF-Token": csrfToken,
"Content-Type": "application/json",
Cookie: joinedCookies,
},
},
);
return data;
} catch (error) {
console.error("❌ Error:", error.message);
console.error("Response:", error.response?.data || "No response data");
}
},
freefire: async (id) => {
if (!id) throw new Error("User ID tidak ditemukan");
try {
const payload = {
campaignUrl: "",
catalogId: 68,
gameId: id,
itemId: 13,
paymentId: 752,
productId: 3,
product_ref: "REG",
product_ref_denom: "REG",
};
const url =
"https://api.duniagames.co.id/api/transaction/v1/top-up/inquiry/store";
const { data } = await axios.post(url, payload);
const gameDetail = {
id,
userName: data?.data?.gameDetail?.userName || "Unknown",
};
return gameDetail;
} catch (error) {
console.error("Error:", error.message);
return [];
}
},
};
export default stalker;