Hướng Dẫn API

Các loại CAPTCHA tùy chỉnh: Gửi các thử thách bất thường cho CaptchaAI

Không phải tất cả CAPTCHA đều là reCAPTCHA hoặc hình ảnh văn bản tiêu chuẩn. CAPTCHA tùy chỉnh yêu cầu các phương pháp sáng tạo để trích xuất và gửi tham số.


Xác định CAPTCHA tùy chỉnh

loại Đặc điểm Cách tiếp cận
CAPTCHA thanh trượt Kéo đến vị trí Ảnh chụp màn hình dưới dạng hình ảnh, sử dụng hướng dẫn văn bản
Câu đố (ghép hình) Kéo mảnh cho vừa Có thể ánh xạ tới cách giải theo phong cách GeeTest
CAPTCHA âm thanh Nghe và gõ Gửi tập tin âm thanh
Xoay hình ảnh Xoay để định hướng đúng Ảnh chụp màn hình + hướng dẫn
Chọn đơn hàng Bấm vào các mục theo thứ tự Sử dụng phương pháp lưới hình ảnh
phương trình toán học Giải số học Sử dụng tham số calc=1
Tương tác tùy chỉnh Tiện ích JS dành riêng cho trang web Ảnh chụp màn hình + văn bản hướng dẫn

Gửi hình ảnh tùy chỉnh kèm theo hướng dẫn

Đối với bất kỳ CAPTCHA trực quan nào, hãy chụp ảnh màn hình và cung cấp hướng dẫn:

import requests
import base64
import time
import os

API_KEY = os.environ["CAPTCHAAI_API_KEY"]

def solve_custom_captcha(image_b64, instructions):
    """Solve any visual CAPTCHA using image + text instructions."""
    resp = requests.post("https://ocr.captchaai.com/in.php", data={
        "key": API_KEY,
        "method": "base64",
        "body": image_b64,
        "textinstructions": instructions,
        "json": 1,
    }, timeout=30)

    result = resp.json()
    if result.get("status") != 1:
        raise RuntimeError(result.get("request"))

    task_id = result["request"]

    time.sleep(10)
    for _ in range(30):
        resp = requests.get("https://ocr.captchaai.com/res.php", params={
            "key": API_KEY, "action": "get",
            "id": task_id, "json": 1,
        }, timeout=15)
        data = resp.json()
        if data.get("status") == 1:
            return data["request"]
        if data["request"] != "CAPCHA_NOT_READY":
            raise RuntimeError(data["request"])
        time.sleep(5)

    raise TimeoutError("Solve timeout")

Vị trí thanh trượt CAPTCHA

CAPTCHA yêu cầu kéo thanh trượt đến một vị trí cụ thể:

# slider_captcha.py
from selenium.webdriver.common.by import By
from selenium.webdriver.common.action_chains import ActionChains

def solve_slider_captcha(driver, captcha_selector):
    """Screenshot slider CAPTCHA and solve via CaptchaAI."""
    captcha = driver.find_element(By.CSS_SELECTOR, captcha_selector)
    image_b64 = captcha.screenshot_as_base64

    result = solve_custom_captcha(
        image_b64,
        "What pixel position should the slider be dragged to? "
        "Return only the X offset number."
    )

    try:
        offset = int(result)
    except ValueError:
        return False

    # Drag slider to position
    slider = driver.find_element(By.CSS_SELECTOR, ".slider-handle")
    ActionChains(driver).click_and_hold(slider).move_by_offset(offset, 0).release().perform()

    return True

CAPTCHA xoay vòng

CAPTCHA trong đó hình ảnh phải được xoay theo đúng hướng:

# rotation_captcha.py

def solve_rotation_captcha(driver, captcha_selector):
    """Solve rotation CAPTCHA."""
    captcha = driver.find_element(By.CSS_SELECTOR, captcha_selector)
    image_b64 = captcha.screenshot_as_base64

    result = solve_custom_captcha(
        image_b64,
        "How many degrees should this image be rotated clockwise "
        "to be in the correct upright orientation? Return only the number."
    )

    try:
        degrees = int(result)
    except ValueError:
        return False

    # Click rotation button the correct number of times
    rotate_btn = driver.find_element(By.CSS_SELECTOR, ".rotate-button")
    clicks = degrees // 90  # Each click rotates 90 degrees

    for _ in range(clicks):
        rotate_btn.click()
        time.sleep(0.3)

    return True

CAPTCHA thứ tự lựa chọn

CAPTCHA trong đó các mục phải được nhấp theo thứ tự cụ thể:

# order_captcha.py

def solve_order_captcha(driver, captcha_selector, item_selector):
    """Solve click-in-order CAPTCHA."""
    captcha = driver.find_element(By.CSS_SELECTOR, captcha_selector)
    image_b64 = captcha.screenshot_as_base64

    result = solve_custom_captcha(
        image_b64,
        "What is the correct order? Return as comma-separated "
        "numbers (1-indexed) representing positions left-to-right, top-to-bottom."
    )

    # Parse order
    try:
        order = [int(x.strip()) for x in result.split(",")]
    except ValueError:
        return False

    # Click items in order
    items = driver.find_elements(By.CSS_SELECTOR, item_selector)
    for idx in order:
        if 1 <= idx <= len(items):
            items[idx - 1].click()
            time.sleep(0.5)

    return True

CAPTCHA âm thanh

Một số trang web cung cấp các lựa chọn thay thế âm thanh:

# audio_captcha.py
import requests

def solve_audio_captcha(audio_url):
    """Download and solve an audio CAPTCHA."""
    # Download audio
    resp = requests.get(audio_url, timeout=30)
    audio_b64 = base64.b64encode(resp.content).decode("ascii")

    # Submit as image with instructions
    # CaptchaAI may support audio via the base64 method
    result = solve_custom_captcha(
        audio_b64,
        "This is an audio CAPTCHA. Transcribe the spoken characters."
    )
    return result

CAPTCHA tiện ích tùy chỉnh

Đối với các tiện ích CAPTCHA hoàn toàn tùy chỉnh:

# custom_widget.py
from selenium import webdriver
from selenium.webdriver.common.by import By

def handle_custom_widget(driver, widget_selector):
    """Handle an unknown custom CAPTCHA widget."""

    # Step 1: Screenshot the entire widget
    widget = driver.find_element(By.CSS_SELECTOR, widget_selector)
    image_b64 = widget.screenshot_as_base64

    # Step 2: Get any visible instructions
    try:
        instructions_el = widget.find_element(By.CSS_SELECTOR, ".instructions, .prompt, p")
        visible_instructions = instructions_el.text
    except Exception:
        visible_instructions = "Solve this CAPTCHA"

    # Step 3: Submit with descriptive instructions
    result = solve_custom_captcha(
        image_b64,
        f"CAPTCHA instructions: {visible_instructions}. "
        f"Return the answer text."
    )

    # Step 4: Try to submit result
    try:
        input_el = widget.find_element(By.CSS_SELECTOR, "input")
        input_el.clear()
        input_el.send_keys(result)
    except Exception:
        # No input — try clicking based on result
        driver.execute_script("""
            var input = document.querySelector('input[name*="captcha"]');
            if (input) input.value = arguments[0];
        """, result)

    return result

Phát hiện loại CAPTCHA

# detector.py
import re

def detect_captcha_type(page_html):
    """Detect which CAPTCHA type is on a page."""
    checks = {
        "recaptcha_v2": r'data-sitekey.*g-recaptcha',
        "recaptcha_v3": r'recaptcha/api\.js\?render=',
        "turnstile": r'cf-turnstile|challenges\.cloudflare\.com/turnstile',
        "geetest": r'gt\b.*challenge|geetest',
        "bls": r'method.*bls|bls-captcha',
        "image_text": r'captcha.*\.(png|jpg|gif|jpeg)',
        "slider": r'slider.*captcha|slide.*verify',
        "audio": r'audio.*captcha|captcha.*audio',
    }

    detected = []
    for captcha_type, pattern in checks.items():
        if re.search(pattern, page_html, re.IGNORECASE):
            detected.append(captcha_type)

    return detected if detected else ["unknown"]

Khắc phục sự cố

Vấn đề Nguyên nhân Cách xử lý
ERROR_CAPTCHA_UNSOLVABLE Hình ảnh không rõ ràng hoặc hướng dẫn mơ hồ Cải thiện chất lượng ảnh chụp màn hình và hướng dẫn
Dạng câu trả lời sai Bộ giải trả về mô tả thay vì giá trị Hãy cụ thể: "Chỉ trả lại số"
Tiện ích tùy chỉnh không được chụp Phần tử bên ngoài khung nhìn Di chuyển đến phần tử trước ảnh chụp màn hình
Tương tác không thành công Tọa độ nhấp chuột sai Ánh xạ giải pháp tới các thành phần UI thực tế một cách cẩn thận

Câu hỏi thường gặp

CaptchaAI có thể giải được bất kỳ loại CAPTCHA nào không?

CaptchaAI hỗ trợ hơn 27.500 loại CAPTCHA. Đối với CAPTCHA tùy chỉnh thực sự mới lạ, phương pháp hướng dẫn bằng hình ảnh + văn bản mang lại mức độ bao phủ tốt nhất.

Điều gì sẽ xảy ra nếu CAPTCHA tùy chỉnh thay đổi thường xuyên?

Sử dụng chức năng phát hiện loại để xác định thử thách hiện tại và định tuyến đến bộ giải thích hợp.

Làm cách nào để nhận được hỗ trợ cho loại CAPTCHA mới?

Liên hệ với bộ phận hỗ trợ CaptchaAI kèm theo hình ảnh mẫu và URL trang web. Các loại mới có thể được thêm vào nền tảng.


Hướng dẫn liên quan

  • Chiến lược giải quyết nhiều ký tự
  • Thực tiễn tốt nhất về mã hóa Base64

Giải bất kỳ CAPTCHA nào —bắt đầu với CaptchaAI.

Os comentários estão desativados para este artigo.