const axios = require("axios") const cheerio = require("cheerio") const BASE = "https://groupsor.link" const HEADERS = { "user-agent": "Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/140.0.0.0 Safari/537.36", "accept-language": "id-ID,id;q=0.9,en-US;q=0.8,en;q=0.7", } function parseGroups(html) { const $ = cheerio.load(html) const groups = [] $(".maindiv").each((_, el) => { const a = $(el).find("a[href*='/group/invite/']").first() const href = a.attr("href") || "" const slug = href.split("/group/invite/")[1]?.trim() if (!slug) return const name = $(el).find("span[style='gtitle']").last().text().trim() const image = $(el).find("img.image").attr("src") || null const category = $(el).find("a[href*='/group/category/']").first().text().trim() const country = $(el).find("a[href*='/group/country/']").first().text().trim() const language = $(el).find("a[href*='/group/language/']").first().text().trim() const description = $(el).find("p.descri").text().replace(/continue reading$/, "").trim() const tags = [] $(el).find("a.innertag").each((_, t) => { const tag = $(t).text().trim() if (tag) tags.push(tag) }) const join_url = `https://chat.whatsapp.com/invite/${slug}` groups.push({ name, slug, category, country, language, description, tags, image, join_url }) }) return groups } async function search(keyword, limit = 10) { const groups = [] let group_no = 0 while (groups.length < limit) { const res = await axios.post( `${BASE}/group/searchmore/${encodeURIComponent(keyword)}`, `group_no=${group_no}`, { headers: { ...HEADERS, "content-type": "application/x-www-form-urlencoded; charset=UTF-8", "x-requested-with": "XMLHttpRequest", referer: `${BASE}/group/search?keyword=${encodeURIComponent(keyword)}`, }, } ) const batch = parseGroups(res.data) if (!batch.length) break groups.push(...batch) group_no += 10 if (batch.length < 10) break } return groups.slice(0, limit) } const [,, keyword, limitArg] = process.argv if (!keyword) { console.error("Usage: node index.js [limit]") process.exit(1) } search(keyword, parseInt(limitArg) || 10).then(r => console.log(JSON.stringify(r, null, 2)))