Integrationen

cURL + CaptchaAI: CLI-CAPTCHA-Lösung

Kein SDK erforderlich. Lösen Sie CAPTCHAs direkt von Ihrem Terminal aus mit cURL und der CaptchaAI REST API. Perfekt für schnelle Tests, CI/CD-Pipelines und Shell-Skripte.

Anforderungen

Anforderung Einzelheiten
cURL Jede moderne Version
jq (optional) Zum Analysieren von Antworten
CaptchaAI API-Schlüssel Holen Sie sich hier eins

Grundlegende Befehle

Überprüfen Sie den Kontostand

curl -s "https://ocr.captchaai.com/res.php?key=YOUR_API_KEY&action=getbalance"

Ausgabe: 1.234

Senden Sie reCAPTCHA v2

curl -s "https://ocr.captchaai.com/in.php?key=YOUR_API_KEY&method=userrecaptcha&googlekey=6Le-wvkS...&pageurl=https://example.com"

Ausgabe: OK|73548291

Umfrage zum Ergebnis

curl -s "https://ocr.captchaai.com/res.php?key=YOUR_API_KEY&action=get&id=73548291"

Ausgabe: OK|03AGdBq24PBCbw... oder CAPCHA_NOT_READY

Bash-Solver-Skript

Erstellen Sie 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

Machen Sie es ausführbar:

chmod +x solve_captcha.sh

Ausführen:

export CAPTCHAAI_API_KEY="your_key_here"
./solve_captcha.sh "6Le-wvkS..." "https://example.com"

Lösen Sie Cloudflare Turnstile

curl -s "https://ocr.captchaai.com/in.php?key=${CAPTCHAAI_API_KEY}&method=turnstile&sitekey=0x4AAAAA...&pageurl=https://example.com"

Bild-CAPTCHA lösen

# 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}"

Für große Bilder verwenden Sie POST:

curl -s -X POST "https://ocr.captchaai.com/in.php" \
  -F "key=${CAPTCHAAI_API_KEY}" \
  -F "method=post" \
  -F "file=@captcha.png"

Lösen und verwenden Sie Token in einer 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}"

Stapelverarbeitung

Mehrere CAPTCHAs aus einer Datei lösen:

#!/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"
}

Fehlerbehebung

Fehler Ursache Beheben
curl: (6) Could not resolve host DNS-Problem Netzwerk prüfen
ERROR_WRONG_USER_KEY Ungültiger API-Schlüssel Suchen Sie nach Leerzeichen/newlines im Schlüssel
Die Antwort ist leer Netzwerk-Timeout Fügen Sie --connect-timeout 30 hinzu
base64: invalid input Problem mit der Binärdatei Verwenden Sie base64 -w 0 (kein Umbruch)

FAQ

Kann ich dies in CI/CD-Pipelines verwenden?

Ja. Legen Sie CAPTCHAAI_API_KEY als CI-Geheimnis fest und rufen Sie das Skript in Ihrer Pipeline auf. Funktioniert mit GitHub Actions, GitLab CI, Jenkins usw.

Ist cURL langsamer als die Verwendung eines SDK?

Der HTTP-Overhead ist identisch. cURL fügt im Vergleich zu Python- oder Node.js-HTTP-Clients keine Latenz hinzu. Die CAPTCHA-Lösungszeit dominiert.

Wie gehe ich mit Sonderzeichen in URLs um?

URL-Kodierungsparameter: Verwenden Sie --data-urlencode mit cURL POST oder curl -G --data-urlencode "pageurl=...".

Verwandte Leitfäden

Diskussionen (0)

Noch keine Kommentare.