Ayogiakbar

SEARCH GROUP WA

Jul 27th, 2025 (edited)
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /**
  2.  * WhatsApp Group Search Scraper
  3.  * Author : gienetic
  4.  * Base   : https://whatsgrouplink.com/
  5.  */
  6.  
  7. const axios = require("axios");
  8. const cheerio = require("cheerio");
  9.  
  10. /**
  11.  * Cari artikel grup berdasarkan keyword
  12.  * @param {string} query - Kata kunci pencarian
  13.  * @returns {Promise<Array<{ title: string, url: string }>>}
  14.  */
  15. async function fetchSearchResults(query) {
  16.   try {
  17.     const searchUrl = `https://whatsgrouplink.com/?s=${encodeURIComponent(query)}`;
  18.     const { data } = await axios.get(searchUrl, { timeout: 10000 });
  19.     const $ = cheerio.load(data);
  20.     const results = [];
  21.  
  22.     $("article").each((_, el) => {
  23.       const title = $(el).find(".entry-title a").text().trim();
  24.       const url = $(el).find(".entry-title a").attr("href");
  25.       if (title && url) {
  26.         results.push({ title, url });
  27.       }
  28.     });
  29.  
  30.     return results;
  31.   } catch (error) {
  32.     console.error("❌ Search error:", error.message);
  33.     return [];
  34.   }
  35. }
  36.  
  37. /**
  38.  * Ambil link grup dari halaman detail
  39.  * @param {string} url - URL artikel grup
  40.  * @returns {Promise<string>}
  41.  */
  42. async function fetchGroupLinks(url) {
  43.   try {
  44.     const { data } = await axios.get(url, { timeout: 10000 });
  45.     const $ = cheerio.load(data);
  46.     const groups = [];
  47.     let counter = 1;
  48.  
  49.     $("ul.wp-block-list li").each((_, el) => {
  50.       const link = $(el).find('a[href*="chat.whatsapp.com"]');
  51.       if (link.length) {
  52.         const href = link.attr("href");
  53.         const name = $(el)
  54.           .text()
  55.           .replace(/\s*-\s*Link$/, "")
  56.           .trim();
  57.         groups.push(`${counter++}). ${name || "Grup WhatsApp"} - ${href}`);
  58.       }
  59.     });
  60.  
  61.     return groups.length
  62.       ? groups.join("\n")
  63.       : "❌ Tidak ditemukan grup WhatsApp pada halaman ini.";
  64.   } catch (error) {
  65.     console.error("❌ Group fetch error:", error.message);
  66.     return "❌ Gagal memproses halaman grup.";
  67.   }
  68. }
  69.  
  70. module.exports = { fetchSearchResults, fetchGroupLinks };
Advertisement
Add Comment
Please, Sign In to add comment