Automatisierungs-Bots erledigen wiederkehrende Aufgaben – Formularübermittlung, Kontoerstellung, Dateneingabe, Überwachung. CAPTCHAs unterbrechen diese Arbeitsabläufe. CaptchaAI löst CAPTCHAs programmgesteuert, sodass Ihre Bots ohne menschliches Eingreifen ausgeführt werden.
Gängige Automatisierungsszenarien
| Szenario | Typisches CAPTCHA | CaptchaAI-Methode |
|---|---|---|
| Formulareinreichung | reCAPTCHA v2 | method=userrecaptcha |
| Kontoregistrierung | reCAPTCHA v2/v3 | method=userrecaptcha |
| Dateneingabeportale | Bild-CAPTCHA | method=base64 |
| Buchung/Reservierung | Cloudflare Turnstile | method=turnstile |
| API-Gateway-Zugriff | Cloudflare Challenge | method=cloudflare_challenge |
Generisches Bot-Framework
Erstellen Sie ein wiederverwendbares CAPTCHA-lösendes Bot-Framework:
import requests
import time
import logging
logger = logging.getLogger(__name__)
class CaptchaBot:
def __init__(self, api_key):
self.api_key = api_key
self.session = requests.Session()
self.session.headers.update({
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36"
})
def solve(self, method, **params):
"""Solve any CAPTCHA type."""
params["key"] = self.api_key
params["method"] = method
resp = requests.get("https://ocr.captchaai.com/in.php", params=params)
if not resp.text.startswith("OK|"):
raise Exception(f"Submit error: {resp.text}")
task_id = resp.text.split("|")[1]
logger.info(f"Task submitted: {task_id}")
for _ in range(60):
time.sleep(5)
result = requests.get("https://ocr.captchaai.com/res.php", params={
"key": self.api_key, "action": "get", "id": task_id
})
if result.text == "CAPCHA_NOT_READY": continue
if result.text.startswith("OK|"): return result.text.split("|")[1]
raise Exception(f"Error: {result.text}")
raise TimeoutError("CAPTCHA solve timed out")
def submit_form(self, url, form_data, captcha_field="g-recaptcha-response",
site_key=None, captcha_method="userrecaptcha"):
"""Submit a form with CAPTCHA solving."""
if site_key:
if captcha_method == "userrecaptcha":
token = self.solve(captcha_method, googlekey=site_key, pageurl=url)
elif captcha_method == "turnstile":
token = self.solve(captcha_method, sitekey=site_key, pageurl=url)
form_data[captcha_field] = token
return self.session.post(url, data=form_data)
Beispiel: Bot zur Formularübermittlung
bot = CaptchaBot("YOUR_API_KEY")
# Submit a contact form protected by reCAPTCHA
result = bot.submit_form(
url="https://example.com/contact",
form_data={
"name": "John Doe",
"email": "john@example.com",
"message": "Inquiry about your service"
},
site_key="6Le-wvkS...",
captcha_method="userrecaptcha"
)
print(f"Form submitted: {result.status_code}")
Beispiel: Mehrstufiger Workflow-Bot
def appointment_booking_bot(date, time_slot, user_info):
bot = CaptchaBot("YOUR_API_KEY")
# Step 1: Load booking page
page = bot.session.get("https://example.com/book")
# Step 2: Select date and time
resp = bot.session.post("https://example.com/book/select", data={
"date": date,
"time": time_slot
})
# Step 3: Fill personal info with CAPTCHA
result = bot.submit_form(
url="https://example.com/book/confirm",
form_data={
"name": user_info["name"],
"email": user_info["email"],
"phone": user_info["phone"],
"date": date,
"time": time_slot
},
site_key="6Le-wvkS...",
captcha_method="userrecaptcha"
)
return result.status_code == 200
# Run
success = appointment_booking_bot(
date="2025-02-15",
time_slot="10:00",
user_info={"name": "John Doe", "email": "john@example.com", "phone": "555-0100"}
)
Beispiel: Dateneingabe-Bot mit Bild-CAPTCHA
import base64
def data_entry_bot(entries, captcha_image_url):
bot = CaptchaBot("YOUR_API_KEY")
for entry in entries:
# Load the form page
page = bot.session.get("https://portal.example.com/entry")
# Download and solve image CAPTCHA
img = bot.session.get(captcha_image_url)
img_b64 = base64.b64encode(img.content).decode()
captcha_text = bot.solve("base64", body=img_b64)
# Submit entry
resp = bot.session.post("https://portal.example.com/entry", data={
**entry,
"captcha": captcha_text
})
logger.info(f"Entry submitted: {resp.status_code}")
time.sleep(random.uniform(2, 5))
Node.js Bot Framework
const axios = require("axios");
class CaptchaBot {
constructor(apiKey) {
this.apiKey = apiKey;
}
async solve(method, params) {
params.key = this.apiKey;
params.method = method;
const submit = await axios.get("https://ocr.captchaai.com/in.php", {
params,
});
const taskId = submit.data.split("|")[1];
while (true) {
await new Promise((r) => setTimeout(r, 5000));
const result = await axios.get("https://ocr.captchaai.com/res.php", {
params: { key: this.apiKey, action: "get", id: taskId },
});
if (result.data === "CAPCHA_NOT_READY") continue;
if (result.data.startsWith("OK|")) return result.data.split("|")[1];
throw new Error(result.data);
}
}
async submitForm(url, formData, siteKey, method = "userrecaptcha") {
const token = await this.solve(method, {
googlekey: siteKey,
pageurl: url,
});
formData["g-recaptcha-response"] = token;
return axios.post(url, new URLSearchParams(formData));
}
}
// Usage
const bot = new CaptchaBot("YOUR_API_KEY");
const result = await bot.submitForm(
"https://example.com/submit",
{ name: "John", email: "john@example.com" },
"6Le-wvkS..."
);
Fehlerbehebung
| Problem | Beheben |
|---|---|
| CAPTCHA-Token abgelehnt | Benutze den Token innerhalb von 120 Sekunden nach der Lösung |
| Bot trotz gültigem Token erkannt | Prüfen Sie Ihren User-Agent und fügen Sie Anfrageverzögerungen hinzu |
| Das Formular erfordert zusätzliche Felder | Überprüfen Sie die Formularquelle auf ausgeblendete Felder (CSRF-Tokens). |
| Der Preis ist auf wiederholte Einreichungen begrenzt | Fügen Sie Verzögerungen hinzu und rotieren Sie Proxys |
FAQ
Können Automatisierungs-Bots mit jedem CAPTCHA-Typ umgehen?
Mit CaptchaAI, ja. Die API unterstützt reCAPTCHA (alle Versionen), Cloudflare Turnstile, GeeTest, hCaptcha, Bild-CAPTCHAs und mehr. Ihr Bot-Framework muss lediglich den Typ erkennen und die richtige Methode aufrufen.
Wie führe ich Bots 24/7 aus?
Verwenden Sie Planungstools (cron, Taskplaner, systemd) oder stellen Sie Funktionen in der Cloud bereit. Die CaptchaAI-API ist rund um die Uhr verfügbar (99,9+ % Uptime).
Was ist mit Bots, die über CAPTCHAs hinaus Anti-Bot-Maßnahmen ergreifen müssen?
CaptchaAI verwaltet die CAPTCHA-Ebene. Für robuste Integrationstests in eigenen Anwendungen bieten sich Selenium-basierte Browser-Setups mit realistischen HTTP-Headern an.
Verwandte Leitfäden
- Automatisierte CAPTCHA-Verwaltung bei der Anmeldung
- CAPTCHA-Automatisierungsskripte
- Playwright CAPTCHA-Handling