Spaces:
Runtime error
Runtime error
import requests | |
def search_darkweb(query: str) -> str: | |
session = requests.Session() | |
session.proxies = { | |
'http': 'socks5h://127.0.0.1:9050', | |
'https': 'socks5h://127.0.0.1:9050' | |
} | |
ahmia_url = f"https://ahmia.fi/search/?q={query}" | |
try: | |
resp = session.get(ahmia_url, timeout=30) | |
if resp.status_code != 200: | |
return "[DarkWeb] Failed to fetch search results." | |
results = [] | |
for line in resp.text.splitlines(): | |
if '.onion' in line and 'href=' in line: | |
start = line.find('http') | |
end = line.find('"', start) | |
if start != -1 and end != -1: | |
link = line[start:end] | |
if '.onion' in link: | |
results.append(link) | |
return '\n'.join(set(results))[:3000] or "[DarkWeb] No .onion links found." | |
except Exception as e: | |
return f"[DarkWeb] Error: {str(e)}" | |