BLS CAPTCHAs usam parâmetros específicos para envio de desafios. Compreender instructions, code e o tratamento de respostas é fundamental para uma solução confiável.
Referência do parâmetro BLS CAPTCHA
| Parâmetro | Obrigatório | Tipo | Descrição |
|---|---|---|---|
method |
Sim | Corda | Deve ser bls |
sitekey |
Sim | Corda | A chave BLS CAPTCHA do site |
pageurl |
Sim | Corda | URL da página que mostra o CAPTCHA |
instructions |
Não | Corda | Instruções de texto da imagem CAPTCHA |
code |
Não | Corda | Código BLS CAPTCHA Identificador /type |
json |
Não | Inteiro | Defina como 1 para respostas JSON |
Extraindo Parâmetros BLS
# extract_bls.py
import re
from selenium import webdriver
from selenium.webdriver.common.by import By
def extract_bls_params(url):
"""Extract BLS CAPTCHA parameters from a page."""
driver = webdriver.Chrome()
driver.get(url)
params = {"pageurl": url}
# Extract sitekey
captcha_el = driver.find_element(By.CSS_SELECTOR, "[data-sitekey], .bls-captcha")
sitekey = captcha_el.get_attribute("data-sitekey")
if sitekey:
params["sitekey"] = sitekey
# Extract instructions if visible
try:
instructions_el = driver.find_element(
By.CSS_SELECTOR, ".captcha-instructions, .captcha-text"
)
params["instructions"] = instructions_el.text.strip()
except Exception:
pass
# Extract code from hidden input or script
page_source = driver.page_source
code_match = re.search(r'captcha_code["\']?\s*[:=]\s*["\']([^"\']+)', page_source)
if code_match:
params["code"] = code_match.group(1)
driver.quit()
return params
# Usage
params = extract_bls_params("https://bls-example.com/appointment")
print(params)
Enviando BLS CAPTCHA para CaptchaAI
Envio Básico
# solve_bls_basic.py
import requests
import time
import os
def solve_bls(sitekey, pageurl, instructions=None, code=None):
"""Solve BLS CAPTCHA via CaptchaAI API."""
api_key = os.environ["CAPTCHAAI_API_KEY"]
payload = {
"key": api_key,
"method": "bls",
"sitekey": sitekey,
"pageurl": pageurl,
"json": 1,
}
# Add optional parameters for higher accuracy
if instructions:
payload["instructions"] = instructions
if code:
payload["code"] = code
resp = requests.post(
"https://ocr.captchaai.com/in.php",
data=payload,
timeout=30,
)
result = resp.json()
if result.get("status") != 1:
raise RuntimeError(f"Submit failed: {result.get('request')}")
task_id = result["request"]
# Poll for result
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("BLS solve timeout")
# Usage
solution = solve_bls(
sitekey="your-bls-sitekey",
pageurl="https://bls-example.com/appointment",
instructions="Select images in the correct order",
)
print(f"Solution: {solution}")
Parâmetro de instruções
O parâmetro instructions informa a CaptchaAI o que o CAPTCHA está perguntando. Isso aprimora a precisão quando o texto do desafio não está incorporado na imagem.
# Common BLS instruction patterns:
instructions_examples = [
"Select images in the correct order",
"Click the images in order from left to right",
"Arrange the images by number",
"Select the matching image",
"Click in the order shown",
]
# Extract instructions from the CAPTCHA image area
def get_instructions_from_page(driver):
"""Try multiple selectors to find instruction text."""
selectors = [
".captcha-instructions",
".bls-captcha-text",
"#captcha-prompt",
".challenge-text",
]
for sel in selectors:
try:
el = driver.find_element(By.CSS_SELECTOR, sel)
text = el.text.strip()
if text:
return text
except Exception:
continue
return None
Parâmetro de código
O parâmetro code especifica a variante BLS CAPTCHA. Algumas implementações de BLS utilizam diferentes tipos de desafios identificados por um código.
# Detect BLS CAPTCHA code from page
def detect_bls_code(page_source):
"""Detect which BLS CAPTCHA code/type is being used."""
patterns = [
(r'captchaType["\']?\s*[:=]\s*["\'](\w+)', "captchaType"),
(r'data-captcha-code["\']?\s*=\s*["\'](\w+)', "data attribute"),
(r'bls_code["\']?\s*[:=]\s*["\'](\w+)', "bls_code"),
]
for pattern, source in patterns:
match = re.search(pattern, page_source)
if match:
return match.group(1)
return None
Fluxo BLS completo com selênio
# full_bls_flow.py
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import os
import re
def solve_bls_with_selenium(url, form_data=None):
"""Complete BLS CAPTCHA flow using Selenium."""
driver = webdriver.Chrome()
driver.get(url)
wait = WebDriverWait(driver, 15)
# Fill any form fields before CAPTCHA
if form_data:
for field_id, value in form_data.items():
el = wait.until(EC.presence_of_element_located((By.ID, field_id)))
el.clear()
el.send_keys(value)
# Extract CAPTCHA parameters
captcha_container = wait.until(
EC.presence_of_element_located((By.CSS_SELECTOR, "[data-sitekey], .bls-captcha"))
)
sitekey = captcha_container.get_attribute("data-sitekey")
# Get instructions
instructions = None
try:
inst_el = driver.find_element(By.CSS_SELECTOR, ".captcha-instructions")
instructions = inst_el.text.strip()
except Exception:
pass
# Solve via API
solution = solve_bls(
sitekey=sitekey,
pageurl=driver.current_url,
instructions=instructions,
)
# Inject solution
driver.execute_script("""
var input = document.querySelector('input[name="captcha-response"], #captcha-response');
if (input) {
input.value = arguments[0];
} else {
var hidden = document.createElement('input');
hidden.type = 'hidden';
hidden.name = 'captcha-response';
hidden.value = arguments[0];
document.forms[0].appendChild(hidden);
}
""", solution)
# Submit form
submit_btn = driver.find_element(By.CSS_SELECTOR, "button[type='submit'], #submit")
submit_btn.click()
# Wait for confirmation
wait.until(EC.url_changes(url))
result_url = driver.current_url
driver.quit()
return result_url
Solução de problemas
| Problema | Causa | Correção |
|---|---|---|
ERROR_BAD_PARAMETERS |
Faltando sitekey ou pageurl |
Verifique se ambos foram extraídos corretamente |
| Solução rejeitada | Instruções não aprovadas | Incluir parâmetro instructions para desafios ambíguos |
| Tipo de CAPTCHA errado | Não é um BLS CAPTCHA | Verifique se é realmente reCAPTCHA ou um tipo personalizado |
sitekey não encontrado |
Carregamento dinâmico | Aguarde a renderização do elemento CAPTCHA antes de extrair |
Perguntas frequentes
As instruções são sempre necessárias?
Não. CaptchaAI pode resolver a maioria dos BLS CAPTCHAs sem instruções. No entanto, passar instruções aprimora a precisão em desafios ambíguos.
E se o parâmetro do código mudar entre as sessões?
Extraia-o novamente a cada vez. O código pode mudar com base na sessão ou localização geográfica.
Quão rápido o BLS CAPTCHA resolve?
Normalmente 10-20 segundos. CaptchaAI relata uma taxa de sucesso de 100% para BLS CAPTCHAs.
Guias Relacionados
Parâmetros mestres BLS CAPTCHA -comece com CaptchaAI.