2026-03-29 13:58:18 +00:00
|
|
|
#!/usr/bin/env python
|
2026-03-29 14:01:35 +00:00
|
|
|
import sys
|
|
|
|
|
import subprocess
|
|
|
|
|
|
|
|
|
|
# Vérifie et installe bs4 si nécessaire
|
|
|
|
|
try:
|
|
|
|
|
from bs4 import BeautifulSoup
|
|
|
|
|
except ImportError:
|
|
|
|
|
print("bs4 non trouvé, installation en cours...")
|
|
|
|
|
subprocess.check_call([sys.executable, "-m", "pip", "install", "beautifulsoup4"])
|
|
|
|
|
from bs4 import BeautifulSoup
|
2026-03-29 13:58:18 +00:00
|
|
|
|
|
|
|
|
import requests
|
2026-03-29 14:01:35 +00:00
|
|
|
import argparse
|
|
|
|
|
|
2026-03-29 13:58:18 +00:00
|
|
|
|
|
|
|
|
def recherche_duckduckgo(query, n=5):
|
|
|
|
|
url = "https://html.duckduckgo.com/html/"
|
|
|
|
|
params = {"q": query}
|
|
|
|
|
|
|
|
|
|
headers = {
|
|
|
|
|
"User-Agent": "Mozilla/5.0"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
response = requests.post(url, data=params, headers=headers)
|
|
|
|
|
soup = BeautifulSoup(response.text, "html.parser")
|
|
|
|
|
|
|
|
|
|
results = []
|
|
|
|
|
|
|
|
|
|
for result in soup.find_all("a", class_="result__a", limit=n):
|
|
|
|
|
title = result.get_text()
|
|
|
|
|
link = result.get("href")
|
|
|
|
|
results.append((title, link))
|
|
|
|
|
|
|
|
|
|
return results
|
|
|
|
|
|
|
|
|
|
|
2026-03-29 14:01:35 +00:00
|
|
|
def main():
|
|
|
|
|
parser = argparse.ArgumentParser(description="Recherche DuckDuckGo simple")
|
|
|
|
|
parser.add_argument("query", type=str, help="Terme de recherche")
|
|
|
|
|
parser.add_argument("-n", "--number", type=int, default=5, help="Nombre de résultats")
|
|
|
|
|
|
|
|
|
|
args = parser.parse_args()
|
2026-03-29 13:58:18 +00:00
|
|
|
|
2026-03-29 14:01:35 +00:00
|
|
|
results = recherche_duckduckgo(args.query, args.number)
|
2026-03-29 13:58:18 +00:00
|
|
|
|
|
|
|
|
for i, (title, link) in enumerate(results, 1):
|
|
|
|
|
print(f"{i}. {title}")
|
|
|
|
|
print(f" {link}\n")
|
2026-03-29 14:01:35 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
|
main()
|