const axios = require('axios') const cheerio = require('cheerio') async function gsmSearch(query) { try { const response = await axios({ method: 'get', url: `https://gsmarena.com/results.php3?sQuickSearch=yes&sName=${query}`, timeout: 30000, headers: { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36', }, }) const $ = cheerio.load(response.data) const result = [] const device = $('.makers').find('li') device.each((i, e) => { const img = $(e).find('img') const id = $(e).find('a').attr('href')?.replace('.php', '') const name = $(e).find('span').html()?.split('
').join(' ') const thumbnail = img.attr('src') const description = img.attr('title') if (id && name) { result.push({ id, name, thumbnail, description, }) } }) return result } catch (error) { throw new Error(error.message || 'Failed to fetch data from GSMArena') } } module.exports = { gsmSearch }