API 教程

使用 Python 和 CaptchaAI 解决 BLS 验证码

BLS CAPTCHA 呈现带有数字指令代码的 3×3 图像网格。您必须选择与指令匹配的单元格。 CaptchaAI 处理图像分析并返回正确的细胞索引。

本指南向您展示如何提取网格图像、为 API 编码、提交到CaptchaAI,然后单击正确的单元格。


先决条件

物品 价值
CaptchaAI API 密钥 验证码网站
Python 3.7+
图书馆 requestsseleniumPillow
目标页面 带有 BLS CAPTCHA 的页面

BLS CAPTCHA 的工作原理

BLS 呈现出 3×3 的网格。每个单元格包含一个小图像。数字指令(例如“664”)告诉用户要选择哪些单元格。单元格从左到右、从上到下编号:

1 | 2 | 3
---------
4 | 5 | 6
---------
7 | 8 | 9

步骤1:提取网格图像和指令

import base64
from selenium import webdriver
from selenium.webdriver.common.by import By

driver = webdriver.Chrome()
driver.get("https://example.com/bls-form")

# Get the instruction code
instruction = driver.find_element(By.CSS_SELECTOR, ".bls-instruction").text
# e.g., "664"

# Get all 9 grid cell images as base64
cells = driver.find_elements(By.CSS_SELECTOR, ".bls-grid img")
images = []
for cell in cells:
    src = cell.get_attribute("src")
    if src.startswith("data:"):
        images.append(src)
    else:
        img_data = requests.get(src).content
        b64 = base64.b64encode(img_data).decode()
        images.append(f"data:image/png;base64,{b64}")

第二步:提交至CaptchaAI

import requests
import time
import json

API_KEY = "YOUR_API_KEY"

# Build the submission data
data = {
    "key": API_KEY,
    "method": "bls",
    "instructions": instruction,
    "json": 1,
}

# Add all 9 images
files = {}
for i, img in enumerate(images):
    files[f"image_base64_{i + 1}"] = (None, img)

response = requests.post("https://ocr.captchaai.com/in.php", data=data, files=files)
result = response.json()

if result["status"] != 1:
    raise Exception(f"Submit failed: {result['request']}")

task_id = result["request"]
print(f"Task submitted: {task_id}")

第 3 步:民意调查解决方案

time.sleep(5)

for _ in range(30):
    result = requests.get("https://ocr.captchaai.com/res.php", params={
        "key": API_KEY,
        "action": "get",
        "id": task_id,
        "json": 1,
    }).json()

    if result["status"] == 1:
        selected_cells = json.loads(result["request"])
        print(f"Selected cells: {selected_cells}")
        # e.g., [1, 4, 7, 8]
        break

    if result["request"] != "CAPCHA_NOT_READY":
        raise Exception(f"Error: {result['request']}")

    time.sleep(5)

第 4 步:单击正确的单元格

# Click the identified cells (0-indexed in Selenium)
for cell_number in selected_cells:
    idx = cell_number - 1  # Convert to 0-based index
    cells[idx].click()

# Submit the form
driver.find_element(By.CSS_SELECTOR, ".bls-submit").click()
print("BLS CAPTCHA solved and submitted")

完整的工作示例

import requests
import time
import json
import base64
from selenium import webdriver
from selenium.webdriver.common.by import By

API_KEY = "YOUR_API_KEY"

# 1. Load the page
driver = webdriver.Chrome()
driver.get("https://example.com/bls-form")

# 2. Extract instruction and images
instruction = driver.find_element(By.CSS_SELECTOR, ".bls-instruction").text
cells = driver.find_elements(By.CSS_SELECTOR, ".bls-grid img")
images = []
for cell in cells:
    src = cell.get_attribute("src")
    if src.startswith("data:"):
        images.append(src)
    else:
        img_data = requests.get(src).content
        b64 = base64.b64encode(img_data).decode()
        images.append(f"data:image/png;base64,{b64}")

# 3. Submit to CaptchaAI
data = {"key": API_KEY, "method": "bls", "instructions": instruction, "json": 1}
files = {f"image_base64_{i+1}": (None, img) for i, img in enumerate(images)}
submit = requests.post("https://ocr.captchaai.com/in.php", data=data, files=files).json()
task_id = submit["request"]

# 4. Poll for result
time.sleep(5)
for _ in range(30):
    poll = requests.get("https://ocr.captchaai.com/res.php", params={
        "key": API_KEY, "action": "get", "id": task_id, "json": 1
    }).json()
    if poll["status"] == 1:
        selected = json.loads(poll["request"])
        break
    if poll["request"] != "CAPCHA_NOT_READY":
        raise Exception(poll["request"])
    time.sleep(5)

# 5. Click and submit
for cell_num in selected:
    cells[cell_num - 1].click()
driver.find_element(By.CSS_SELECTOR, ".bls-submit").click()
print(f"Solved: clicked cells {selected}")
driver.quit()

预期输出:

Solved: clicked cells [1, 4, 7, 8]

常见错误

错误 原因 处理方式
ERROR_BAD_PARAMETERS 图片缺失或说明无效 确保提供所有 9 张图片和说明
CAPCHA_NOT_READY 仍在处理中 继续每 5 秒轮询一次
ERROR_ZERO_BALANCE 没有资金 为您的CaptchaAI账户充值

常问问题

BLS CAPTCHA 的求解速度有多快?

通常为 5-15 秒,比 reCAPTCHA 或 GeeTest 快。

图像应该采用什么格式?

Base64 编码的数据 URI(例如 data:image/png;base64,...)。支持 JPG、PNG 和 GIF。

我可以将完整网格作为一张图像发送吗?

不需要。BLS 要求所有 9 个单独的细胞图像单独发送。


相关指南


开始用 CaptchaAI → 求解 BLS CAPTCHA


后续阅读

该文章已禁用评论。