Use Cases

Đăng nhập tự động Xử lý CAPTCHA với CaptchaAI

Các trang đăng nhập là nơi phổ biến nhất để gặp CAPTCHA. Cho dù đó là reCAPTCHA v2, v3, Turnstile hay CAPTCHA hình ảnh, CaptchaAI đều giải quyết được thách thức trong khi tính năng tự động hóa của bạn xử lý việc điền và gửi biểu mẫu.

Các loại CAPTCHA đăng nhập phổ biến

CAPTCHA Nó xuất hiện như thế nào Phương pháp CaptchaAI
reCAPTCHA v2 Hộp kiểm hoặc thử thách trước khi gửi method=userrecaptcha
reCAPTCHA v3 Tính điểm vô hình, chặn người dùng có điểm thấp method=userrecaptcha&version=v3
Cloudflare Turnstile Widget trước hình thức đăng nhập method=turnstile
CAPTCHA hình ảnh Hình ảnh văn bản để gõ method=base64

Phương pháp 1: Yêu cầu HTTP (Không có trình duyệt)

Đối với các biểu mẫu đăng nhập chấp nhận yêu cầu POST tiêu chuẩn:

import requests
import time

API_KEY = "YOUR_API_KEY"

def solve_recaptcha(site_key, page_url):
    resp = requests.get("https://ocr.captchaai.com/in.php", params={
        "key": API_KEY, "method": "userrecaptcha",
        "googlekey": site_key, "pageurl": page_url
    })
    task_id = resp.text.split("|")[1]
    for _ in range(60):
        time.sleep(5)
        result = requests.get("https://ocr.captchaai.com/res.php", params={
            "key": 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(result.text)
    raise TimeoutError()

# Login flow
session = requests.Session()
login_url = "https://staging.example.com/qa-login"

# Load login page to get cookies and site key
page = session.get(login_url)
# Extract site_key from the page HTML...
site_key = "6Le-wvkS..."

# Solve CAPTCHA
token = solve_recaptcha(site_key, login_url)

# Submit login form
resp = session.post(login_url, data={
    "username": "user@example.com",
    "password": "your_password",
    "g-recaptcha-response": token
})

if resp.url != login_url:
    print("Login successful!")
    # session now has auth cookies for subsequent requests

Cách 2: Selenium (Python)

Đối với các trang đăng nhập yêu cầu thực thi JavaScript:

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 requests
import time

API_KEY = "YOUR_API_KEY"

options = webdriver.ChromeOptions()
options.add_argument("")
driver = webdriver.Chrome(options=options)

# Navigate to login page
driver.get("https://staging.example.com/qa-login")
wait = WebDriverWait(driver, 10)

# Fill in credentials
username_field = wait.until(EC.presence_of_element_located((By.NAME, "username")))
username_field.send_keys("user@example.com")
driver.find_element(By.NAME, "password").send_keys("your_password")

# Extract site key and solve
recaptcha = driver.find_element(By.CLASS_NAME, "g-recaptcha")
site_key = recaptcha.get_attribute("data-sitekey")

token = solve_recaptcha(site_key, driver.current_url)

# Inject token
driver.execute_script(
    f"document.getElementById('g-recaptcha-response').innerHTML = '{token}';"
)

# Submit
driver.find_element(By.CSS_SELECTOR, 'button[type="submit"]').click()
wait.until(EC.url_changes(driver.current_url))
print(f"Logged in! Now at: {driver.current_url}")

Phương pháp 3: Puppeteer (Node.js)

const puppeteer = require("puppeteer");
const axios = require("axios");

const API_KEY = "YOUR_API_KEY";

async function solveRecaptcha(siteKey, pageUrl) {
  const submit = await axios.get("https://ocr.captchaai.com/in.php", {
    params: {
      key: API_KEY,
      method: "userrecaptcha",
      googlekey: siteKey,
      pageurl: pageUrl,
    },
  });
  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: API_KEY, 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 () => {
  const browser = await puppeteer.launch({ headless: "new" });
  const page = await browser.newPage();
  await page.goto("https://staging.example.com/qa-login");

  // Fill credentials
  await page.type("#username", "user@example.com");
  await page.type("#password", "your_password");

  // Get site key and solve
  const siteKey = await page.$eval(".g-recaptcha", (el) =>
    el.getAttribute("data-sitekey")
  );
  const token = await solveRecaptcha(siteKey, page.url());

  // Inject and submit
  await page.evaluate(
    (t) => (document.getElementById("g-recaptcha-response").innerHTML = t),
    token
  );
  await page.click('button[type="submit"]');
  await page.waitForNavigation();

  console.log("Logged in:", page.url());
  await browser.close();
})();

Xử lý đa yếu tố + CAPTCHA

Một số trang web kết hợp CAPTCHA với xác thực đa yếu tố:

# Step 1: Solve CAPTCHA and submit login
token = solve_recaptcha(site_key, login_url)
resp = session.post(login_url, data={
    "username": "user@example.com",
    "password": "your_password",
    "g-recaptcha-response": token
})

# Step 2: Handle MFA page (if redirected)
if "verify" in resp.url or "mfa" in resp.url:
    # Your MFA code logic here
    mfa_code = get_mfa_code()
    resp = session.post(resp.url, data={"code": mfa_code})

# Step 3: Verify logged in
assert "dashboard" in resp.url

Khắc phục sự cố

Vấn đề Nguyên nhân Cách xử lý
Đăng nhập trở lại trang CAPTCHA Mã thông báo đã hết hạn Giải quyết và gửi trong vòng 60 giây
"Thông tin đăng nhập không hợp lệ" với mật khẩu chính xác Mã thông báo CSRF bị thiếu Trích xuất và bao gồm mã thông báo CSRF từ trang đăng nhập
Phiên bị mất sau khi đăng nhập Cookie không tồn tại Sử dụng requests.Session() hoặc cookie trình duyệt
Khối reCAPTCHA v3 bất chấp mã thông báo Điểm quá thấp CaptchaAI tối ưu hóa để đạt điểm cao; xác minh tham số hành động

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

Tôi có thể tự động đăng nhập vào bất kỳ trang web nào không?

CaptchaAI xử lý thành phần CAPTCHA. Quá trình tự động hóa của bạn cần tự xử lý biểu mẫu đăng nhập (điền vào các trường, gửi, quản lý cookie). Tính hợp pháp phụ thuộc vào quyền truy cập vào tài khoản của bạn.

Tôi có cần trình duyệt để tự động đăng nhập không?

Không phải lúc nào cũng vậy. Nhiều trang đăng nhập chấp nhận các yêu cầu HTTP POST tiêu chuẩn. Chỉ sử dụng trình duyệt khi đăng nhập yêu cầu thực thi JavaScript hoặc tương tác phức tạp.

Làm cách nào để xử lý việc bảo trì phiên sau khi đăng nhập?

Sử dụng requests.Session() bằng Python hoặc duy trì cookie trong phiên bản trình duyệt của bạn. Cookie phiên từ quá trình đăng nhập là cần thiết cho tất cả các yêu cầu được xác thực tiếp theo.

Hướng dẫn liên quan

  • Xử lý CAPTCHA Selenium bằng Python
  • Puppeteer giải CAPTCHA bằng Node.js
  • Nhà soạn kịch Xử lý CAPTCHA
Os comentários estão desativados para este artigo.

Postagens relacionadas

Reference Tính bền vững phiên trình duyệt cho luồng QA CAPTCHA của bạn
Duy trì phiên trình duyệt qua nhiều bước trong kiểm thử QA CAPTCHA trên staging của bạn để giảm gián đoạn và tăng độ tái lập.

Duy trì phiên trình duyệt qua nhiều bước trong kiểm thử QA CAPTCHA trên staging của bạn để giảm gián đoạn và t...

Apr 30, 2026
Integrations Tách biệt hồ sơ trình duyệt cho QA với CaptchaAI
Tách cookie, storage, tài khoản kiểm thử và cấu hình CAPTCHA theo từng hồ sơ trình duyệt để giữ cho kiểm thử QA trong staging sạch và có thể tái lập.

Tách cookie, storage, tài khoản kiểm thử và cấu hình CAPTCHA theo từng hồ sơ trình duyệt để giữ cho kiểm thử Q...

Apr 29, 2026
API Tutorials Bash Script + cURL + CaptchaAI: Tự động hóa Shell CAPTCHA
Hướng dẫn từng bước cho Bash Script + c URL + Captcha AI: Tự động hóa Shell CAPTCHA, với các ví dụ có thể sử dụng lại trực tiếp và quy trình làm việc Captcha AI...

Hướng dẫn từng bước cho Bash Script + c URL + Captcha AI: Tự động hóa Shell CAPTCHA, với các ví dụ có thể sử d...

Apr 26, 2026