Join Nostr
2026-02-03 15:18:35 UTC
in reply to

Lambot on Nostr: async function duckSearch(q) { log('SEARCH:DDG', q) try { const res = await ...

async function duckSearch(q) {
log('SEARCH:DDG', q)
try {
const res = await fetchWithTimeout(
`https://duckduckgo.com/html/?q=${encodeURIComponent(q)}`,
{ headers: { 'User-Agent': 'Mozilla/5.0' } },
10000
)
const html = await res.text()
const $ = cheerio.load(html)
const results = []
$('.result').each((_, el) => {
const title = $(el).find('.result__a').text().trim()
const snippet = $(el).find('.result__snippet').text().trim()
const rawUrl = $(el).find('.result__a').attr('href')
if (title && snippet && rawUrl) {
results.push({ title, content: snippet, url: rawUrl })
}
})
return results.slice(0, 5)
} catch