Aucun SDK nécessaire. Résolvez les CAPTCHA directement depuis votre terminal avec cURL et l'API REST CaptchaAI. Parfait pour les tests rapides, les pipelines CI/CD et les scripts shell.
Exigences
| Exigence | Détails |
|---|---|
| boucle | Toute version moderne |
| jq (facultatif) | Pour analyser les réponses |
| Clé API CaptchaAI | Obtenez-en un ici |
Commandes de base
Vérifier le solde
curl -s "https://ocr.captchaai.com/res.php?key=YOUR_API_KEY&action=getbalance"
Sortie : 1.234
Soumettre reCAPTCHA v2
curl -s "https://ocr.captchaai.com/in.php?key=YOUR_API_KEY&method=userrecaptcha&googlekey=6Le-wvkS...&pageurl=https://example.com"
Sortie : OK|73548291
Sondage pour le résultat
curl -s "https://ocr.captchaai.com/res.php?key=YOUR_API_KEY&action=get&id=73548291"
Sortie : OK|03AGdBq24PBCbw... ou CAPCHA_NOT_READY
Script du solveur Bash
Créez solve_captcha.sh :
#!/bin/bash
set -euo pipefail
API_KEY="${CAPTCHAAI_API_KEY:?Set CAPTCHAAI_API_KEY environment variable}"
BASE_URL="https://ocr.captchaai.com"
solve_recaptcha() {
local site_key="$1"
local page_url="$2"
local timeout="${3:-300}"
# Submit
local response
response=$(curl -s "${BASE_URL}/in.php?key=${API_KEY}&method=userrecaptcha&googlekey=${site_key}&pageurl=${page_url}")
if [[ ! "$response" == OK|* ]]; then
echo "ERROR: Submit failed: $response" >&2
return 1
fi
local task_id="${response#OK|}"
echo "Submitted task: $task_id" >&2
# Poll
local deadline=$((SECONDS + timeout))
while (( SECONDS < deadline )); do
sleep 5
local result
result=$(curl -s "${BASE_URL}/res.php?key=${API_KEY}&action=get&id=${task_id}")
if [[ "$result" == "CAPCHA_NOT_READY" ]]; then
echo "Waiting..." >&2
continue
fi
if [[ "$result" == OK|* ]]; then
echo "${result#OK|}"
return 0
fi
echo "ERROR: Solve failed: $result" >&2
return 1
done
echo "ERROR: Timeout after ${timeout}s" >&2
return 1
}
# Usage: ./solve_captcha.sh SITE_KEY PAGE_URL
if [[ $# -ge 2 ]]; then
solve_recaptcha "$1" "$2"
fi
Rendez-le exécutable :
chmod +x solve_captcha.sh
Exécuter :
export CAPTCHAAI_API_KEY="your_key_here"
./solve_captcha.sh "6Le-wvkS..." "https://example.com"
Résoudre Cloudflare Turnstile
curl -s "https://ocr.captchaai.com/in.php?key=${CAPTCHAAI_API_KEY}&method=turnstile&sitekey=0x4AAAAA...&pageurl=https://example.com"
Résoudre le CAPTCHA d’image
# Encode image to base64
IMAGE_B64=$(base64 -w 0 captcha.png)
# Submit
curl -s "https://ocr.captchaai.com/in.php?key=${CAPTCHAAI_API_KEY}&method=base64&body=${IMAGE_B64}"
Pour les grandes images, utilisez POST :
curl -s -X POST "https://ocr.captchaai.com/in.php" \
-F "key=${CAPTCHAAI_API_KEY}" \
-F "method=post" \
-F "file=@captcha.png"
Résoudre et utiliser le jeton dans un seul pipeline
#!/bin/bash
# Solve CAPTCHA and submit form in one pipeline
API_KEY="${CAPTCHAAI_API_KEY}"
SITE_KEY="6Le-wvkS..."
TARGET_URL="https://example.com/login"
# Solve
TOKEN=$(./solve_captcha.sh "$SITE_KEY" "$TARGET_URL")
if [[ -z "$TOKEN" ]]; then
echo "Failed to solve CAPTCHA"
exit 1
fi
# Submit form with token
curl -s -X POST "$TARGET_URL" \
-d "username=user" \
-d "password=pass" \
-d "g-recaptcha-response=${TOKEN}"
Traitement par lots
Résolvez plusieurs CAPTCHA à partir d'un fichier :
#!/bin/bash
# Input file: urls.txt (one URL per line)
while IFS= read -r url; do
echo "Processing: $url"
TOKEN=$(./solve_captcha.sh "6Le-wvkS..." "$url")
if [[ -n "$TOKEN" ]]; then
echo "$url,$TOKEN" >> results.csv
echo " Solved ✓"
else
echo " Failed ✗"
fi
done < urls.txt
PowerShell (Windows)
$ApiKey = $env:CAPTCHAAI_API_KEY
$BaseUrl = "https://ocr.captchaai.com"
# Submit
$response = Invoke-RestMethod "${BaseUrl}/in.php?key=${ApiKey}&method=userrecaptcha&googlekey=6Le-wvkS...&pageurl=https://example.com"
if ($response -match '^OK\|(.+)$') {
$taskId = $Matches[1]
Write-Host "Task: $taskId"
} else {
Write-Error "Submit failed: $response"
exit 1
}
# Poll
do {
Start-Sleep -Seconds 5
$result = Invoke-RestMethod "${BaseUrl}/res.php?key=${ApiKey}&action=get&id=${taskId}"
} while ($result -eq 'CAPCHA_NOT_READY')
if ($result -match '^OK\|(.+)$') {
$token = $Matches[1]
Write-Host "Token: $token"
} else {
Write-Error "Solve failed: $result"
}
Dépannage
| Erreur | Parce que | Corriger |
|---|---|---|
curl: (6) Could not resolve host |
Problème DNS | Vérifier le réseau |
ERROR_WRONG_USER_KEY |
Mauvaise clé API | Vérifiez les espaces/newlines dans la clé |
| La réponse est vide | Délai d'expiration du réseau | Ajouter --connect-timeout 30 |
base64: invalid input |
Problème de fichier binaire | Utilisez base64 -w 0 (sans emballage) |
FAQ
Puis-je l'utiliser dans les pipelines CI/CD ?
Oui. Définissez CAPTCHAAI_API_KEY comme secret CI et appelez le script dans votre pipeline. Fonctionne avec GitHub Actions, GitLab CI, Jenkins, etc.
CURL est-il plus lent que l'utilisation d'un SDK ?
La surcharge HTTP est identique. cURL n'ajoute aucune latence par rapport aux clients HTTP Python ou Node.js. Le temps de résolution du CAPTCHA domine.
Comment gérer les caractères spéciaux dans les URL ?
Paramètres d'encodage d'URL : utilisez --data-urlencode avec cURL POST ou curl -G --data-urlencode "pageurl=...".
Guides connexes
- Axios + CaptchaAI (pas de navigateur)
- Configuration et authentification de la clé API
- Formats de réponse API