Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * WhatsApp Group Search Scraper
- * Author : gienetic
- * Base : https://whatsgrouplink.com/
- */
- const axios = require("axios");
- const cheerio = require("cheerio");
- /**
- * Cari artikel grup berdasarkan keyword
- * @param {string} query - Kata kunci pencarian
- * @returns {Promise<Array<{ title: string, url: string }>>}
- */
- async function fetchSearchResults(query) {
- try {
- const searchUrl = `https://whatsgrouplink.com/?s=${encodeURIComponent(query)}`;
- const { data } = await axios.get(searchUrl, { timeout: 10000 });
- const $ = cheerio.load(data);
- const results = [];
- $("article").each((_, el) => {
- const title = $(el).find(".entry-title a").text().trim();
- const url = $(el).find(".entry-title a").attr("href");
- if (title && url) {
- results.push({ title, url });
- }
- });
- return results;
- } catch (error) {
- console.error("❌ Search error:", error.message);
- return [];
- }
- }
- /**
- * Ambil link grup dari halaman detail
- * @param {string} url - URL artikel grup
- * @returns {Promise<string>}
- */
- async function fetchGroupLinks(url) {
- try {
- const { data } = await axios.get(url, { timeout: 10000 });
- const $ = cheerio.load(data);
- const groups = [];
- let counter = 1;
- $("ul.wp-block-list li").each((_, el) => {
- const link = $(el).find('a[href*="chat.whatsapp.com"]');
- if (link.length) {
- const href = link.attr("href");
- const name = $(el)
- .text()
- .replace(/\s*-\s*Link$/, "")
- .trim();
- groups.push(`${counter++}). ${name || "Grup WhatsApp"} - ${href}`);
- }
- });
- return groups.length
- ? groups.join("\n")
- : "❌ Tidak ditemukan grup WhatsApp pada halaman ini.";
- } catch (error) {
- console.error("❌ Group fetch error:", error.message);
- return "❌ Gagal memproses halaman grup.";
- }
- }
- module.exports = { fetchSearchResults, fetchGroupLinks };
Advertisement
Add Comment
Please, Sign In to add comment