File size: 526 Bytes
d2bcd1f
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
from duckduckgo_search import DDGS

def search_web(query: str, max_results: int = 5) -> str:
    try:
        with DDGS() as ddgs:
            results = list(ddgs.text(query, max_results=max_results))
        if not results:
            return "لا توجد نتائج بحث."
        formatted = "\n".join([f"- {r['title']}: {r['href']}\n  {r['body']}" for r in results])
        return f"🔍 نتائج البحث لـ '{query}':\n{formatted}"
    except Exception as e:
        return f"خطأ في البحث: {str(e)}"