Kembali ke Beranda
Gistify Snippet
kyiov
Feb 15·1 file(s)
Public

Uploaded via Joy AI Bot | 2/15/2026, 11:34:03 AM

synced from github gist Scrape GSMArena

#scraper
Scrape GSMArenaplaintext
93 baris
1/*
2 * ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
3 * 🟢 J O Y A I B O T - S O U R C E C O D E
4 * ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
5 * 👤 Author : Har
6 * 📅 Fetched : 2/15/2026, 11:30:40 AM
7 * 📂 File : gsmarena.js
8 * ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
9 */
10
11/**
12 * @module plugins/internet/gsmarena
13 * @description Scrape Smartphone Specs from GSMArena
14 */
15
16import axios from 'axios'
17import * as cheerio from 'cheerio'
18
19let handler = async (m, { conn, text, usedPrefix, command }) => {
20 if (!text) return m.reply(`📱 Cari HP apa?\nContoh: ${usedPrefix + command} iphone 15`)
21
22 await conn.sendMessage(m.chat, { react: { text: '📱', key: m.key } })
23
24 try {
25 // 1. Search
26 const searchUrl = `https://www.gsmarena.com/results.php3?sQuickSearch=yes&sName=${encodeURIComponent(text)}`
27 const { data: searchData } = await axios.get(searchUrl)
28 const $ = cheerio.load(searchData)
29
30 // Get first result
31 const firstResult = $('.makers ul li').first()
32 const relativeLink = firstResult.find('a').attr('href')
33 const name = firstResult.find('span').html()?.replace(/<br>/g, ' ') || firstResult.text()
34 const img = firstResult.find('img').attr('src')
35
36 if (!relativeLink) return m.reply('❌ HP tidak ditemukan.')
37
38 const link = `https://www.gsmarena.com/${relativeLink}`
39
40 await m.reply(`🔍 Menemukan: *${name}*\n⏳ Mengambil spesifikasi...`)
41
42 // 2. Scrape Detail
43 const { data: detailData } = await axios.get(link)
44 const $$ = cheerio.load(detailData)
45
46 let specs = {}
47 let currentCategory = ''
48
49 $$('#specs-list table tr').each((i, el) => {
50 const th = $$(el).find('th')
51 if (th.length > 0) currentCategory = th.text().trim()
52
53 const ttl = $$(el).find('.ttl a').text().trim() || $$(el).find('.ttl').text().trim()
54 const nfo = $$(el).find('.nfo').text().trim().replace(/\n/g, ', ')
55
56 if (currentCategory && ttl && nfo) {
57 if (!specs[currentCategory]) specs[currentCategory] = []
58 specs[currentCategory].push(`${ttl}: ${nfo}`)
59 }
60 })
61
62 // Formatting Output
63 let caption = `📱 *GSMARENA SPECS* 📱\n\n`
64 caption += `🏷️ *Nama:* ${name}\n`
65 caption += `🔗 *Link:* ${link}\n\n`
66
67 const keyCategories = ['Launch', 'Body', 'Display', 'Platform', 'Memory', 'Main Camera', 'Selfie camera', 'Battery', 'Features']
68
69 keyCategories.forEach(cat => {
70 if (specs[cat]) {
71 caption += `*${cat.toUpperCase()}*\n`
72 caption += specs[cat].map(s => `- ${s}`).join('\n')
73 caption += '\n\n'
74 }
75 })
76
77 await conn.sendMessage(m.chat, {
78 image: { url: img },
79 caption
80 }, { quoted: m })
81
82 } catch (e) {
83 console.error(e)
84 m.reply('❌ Terjadi kesalahan saat mengambil data GSMArena.')
85 }
86}
87
88handler.help = ['gsmarena <hp>', 'spek <hp>']
89handler.tags = ['internet', 'search']
90handler.command = ['gsmarena', 'spek', 'spesifikasi']
91handler.limit = true
92
93export default handler
Diskusi & Komentar0

Belum ada komentar — jadilah yang pertama memberikan masukan atau diskusi kode.

Masuk dengan akun GitHub untuk menulis komentar dan berdiskusi.