const axios = require('axios'); const cheerio = require('cheerio'); const userAgents = [ 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36', 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.0.0 Safari/537.36', 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36', 'Mozilla/5.0 (iPhone; CPU iPhone OS 17_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.1 Mobile/15E148 Safari/604.1' ]; const getHeaders = () => ({ 'User-Agent': userAgents[Math.floor(Math.random() * userAgents.length)], 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8', 'Accept-Language': 'en-US,en;q=0.5', 'DNT': '1', 'Connection': 'keep-alive', 'Upgrade-Insecure-Requests': '1' }); /** * UPLINK_PRIMARY: DuckDuckGo Lite */ const tryDDG = async (query) => { try { const response = await axios.get(`https://duckduckgo.com/lite/?q=${encodeURIComponent(query)}`, { headers: getHeaders(), timeout: 5000 }); if (response.data.includes('Unfortunately, bots use DuckDuckGo too')) return null; const $ = cheerio.load(response.data); const results = []; $('a.result-link').each((i, el) => { if (i >= 3) return false; const title = $(el).text().trim(); let url = $(el).attr('href'); if (url && title) { if (url.startsWith('//')) url = 'https:' + url; results.push({ url, title, snippet: "Verified DDG Uplink." }); } }); return results.length > 0 ? results : null; } catch (e) { return null; } }; /** * UPLINK_SECONDARY: Ask.com (Highly Leniency) */ const tryAsk = async (query) => { try { const response = await axios.get(`https://www.ask.com/web?q=${encodeURIComponent(query)}`, { headers: getHeaders(), timeout: 5000 }); const $ = cheerio.load(response.data); const results = []; $('.PartialSearchResults-item').each((i, el) => { if (i >= 3) return false; const title = $(el).find('.PartialSearchResults-item-title').text().trim(); const url = $(el).find('.PartialSearchResults-item-title a').attr('href'); const snippet = $(el).find('.PartialSearchResults-item-abstract').text().trim(); if (title && url) { results.push({ url, title, snippet: snippet || "Live data packet." }); } }); return results.length > 0 ? results : null; } catch (e) { return null; } }; /** * UPLINK_TERTIARY: Bing (Mobile Interface) */ const tryBing = async (query) => { try { const response = await axios.get(`https://www.bing.com/search?q=${encodeURIComponent(query)}`, { headers: getHeaders(), timeout: 5000 }); const $ = cheerio.load(response.data); const results = []; $('.b_algo').each((i, el) => { if (i >= 3) return false; const title = $(el).find('h2').text().trim(); const url = $(el).find('a').attr('href'); if (title && url && url.startsWith('http')) { results.push({ url, title, snippet: "Bing Neural Link." }); } }); return results.length > 0 ? results : null; } catch (e) { return null; } }; /** * FREE_UNLIMITED_SEARCH * Multi-Sector pivoting to ensure data retrieval. */ exports.searchWeb = async (query) => { console.log(`[Neural_Search] Initiating multi-sector scan for: ${query}`); // Try DDG first let results = await tryDDG(query); // If DDG fails, pivot to Ask if (!results) { console.log("[Neural_Search] Primary sector (DDG) shielded. Pivoting to Ask.com..."); results = await tryAsk(query); } // If Ask fails, pivot to Bing if (!results) { console.log("[Neural_Search] Secondary sector (Ask) offline. Pivoting to Bing..."); results = await tryBing(query); } if (!results || results.length === 0) { return "[SEARCH_OFFLINE]: All web sectors are temporarily shielded by bot protection. The collective is unable to establish a live link at this millisecond."; } return results.map(r => `SOURCE: ${r.url}\nTITLE: ${r.title}\nINFO: ${r.snippet}`).join('\n\n'); };