Tích Hợp

Smartproxy + CaptchaAI: Thiết lập proxy dân dụng để giải CAPTCHA

Smartproxy cung cấp hơn 55 triệu IP dân cư với một cổng xoay đơn giản. Kết hợp với CaptchaAI để giải CAPTCHA, bạn sẽ có được một quy trình đáng tin cậy để truy cập các trang web được bảo vệ CAPTCHA thông qua các IP dân cư sạch.


Các loại proxy proxy thông minh

loại Bể bơi Tốt nhất cho Tỷ lệ CAPTCHA
Khu dân cư 55 triệu+ IP Cạo chung Thấp
Trung tâm dữ liệu 100K+ IP Dữ liệu tốc độ cao Trung bình-cao
Điện thoại di động 10 triệu+ IP Trang web dành riêng cho thiết bị di động Rất thấp
ISP Tĩnh cấp dân cư Công việc nặng nhọc Thấp

Cài đặt Python

Yêu cầu cơ bản

import requests
import time

SMARTPROXY_USER = "spuser"
SMARTPROXY_PASS = "sppassword"
SMARTPROXY_HOST = "gate.smartproxy.com"
SMARTPROXY_PORT = 10001

CAPTCHAAI_KEY = "YOUR_API_KEY"
CAPTCHAAI_URL = "https://ocr.captchaai.com"

proxies = {
    "http": f"http://{SMARTPROXY_USER}:{SMARTPROXY_PASS}@{SMARTPROXY_HOST}:{SMARTPROXY_PORT}",
    "https": f"http://{SMARTPROXY_USER}:{SMARTPROXY_PASS}@{SMARTPROXY_HOST}:{SMARTPROXY_PORT}",
}

def fetch_page(url):
    return requests.get(url, proxies=proxies, timeout=30)

def solve_captcha(site_url, sitekey, captcha_type="recaptcha_v2"):
    submit_data = {
        "key": CAPTCHAAI_KEY,
        "pageurl": site_url,
        "json": 1,
    }

    if captcha_type == "turnstile":
        submit_data["method"] = "turnstile"
        submit_data["sitekey"] = sitekey
    else:
        submit_data["method"] = "userrecaptcha"
        submit_data["googlekey"] = sitekey

    resp = requests.post(f"{CAPTCHAAI_URL}/in.php", data=submit_data)
    data = resp.json()
    if data["status"] != 1:
        raise Exception(f"Submit failed: {data['request']}")

    task_id = data["request"]

    for _ in range(60):
        time.sleep(5)
        resp = requests.get(f"{CAPTCHAAI_URL}/res.php", params={
            "key": CAPTCHAAI_KEY,
            "action": "get",
            "id": task_id,
            "json": 1,
        })
        data = resp.json()
        if data["request"] == "CAPCHA_NOT_READY":
            continue
        if data["status"] == 1:
            return data["request"]
        raise Exception(f"Solve: {data['request']}")

    raise TimeoutError("Timeout")

Phiên dính

import random
import string

def get_sticky_proxy(session_duration_minutes=10):
    """Create a sticky session proxy (same IP for duration)."""
    session_id = "".join(random.choices(string.ascii_lowercase + string.digits, k=8))

    proxy_url = (
        f"http://{SMARTPROXY_USER}"
        f"-session-{session_id}"
        f"-sessionduration-{session_duration_minutes}"
        f":{SMARTPROXY_PASS}@{SMARTPROXY_HOST}:{SMARTPROXY_PORT}"
    )

    return {"http": proxy_url, "https": proxy_url}

# Use same IP for entire CAPTCHA workflow
sticky = get_sticky_proxy(session_duration_minutes=10)

# Page load
resp = requests.get("https://staging.example.com/qa-form", proxies=sticky)

# Solve CAPTCHA
token = solve_captcha("https://staging.example.com/qa-form", "SITEKEY_HERE")

# Submit with same IP
resp = requests.post(
    "https://target.com/submit",
    data={"g-recaptcha-response": token},
    proxies=sticky,
)

Nhắm mục tiêu theo quốc gia

# Smartproxy country targeting via username
def get_country_proxy(country_code):
    proxy_url = (
        f"http://{SMARTPROXY_USER}"
        f"-country-{country_code}"
        f":{SMARTPROXY_PASS}@{SMARTPROXY_HOST}:{SMARTPROXY_PORT}"
    )
    return {"http": proxy_url, "https": proxy_url}

# US proxy
us_proxy = get_country_proxy("us")

# UK proxy
uk_proxy = get_country_proxy("gb")

# Germany proxy
de_proxy = get_country_proxy("de")

Tích hợp Selenium

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

def create_smartproxy_driver(country=None, sticky_session=None):
    proxy_user = SMARTPROXY_USER
    if country:
        proxy_user += f"-country-{country}"
    if sticky_session:
        proxy_user += f"-session-{sticky_session}"

    proxy_url = f"{proxy_user}:{SMARTPROXY_PASS}@{SMARTPROXY_HOST}:{SMARTPROXY_PORT}"

    options = webdriver.ChromeOptions()
    options.add_argument(f"--proxy-server=http://{SMARTPROXY_HOST}:{SMARTPROXY_PORT}")
    options.add_argument("")
    options.add_argument("--window-size=1920,1080")

    # For authenticated proxies, use seleniumwire or extension
    return webdriver.Chrome(options=options)

def scrape_with_captcha(url, country="us"):
    session_id = "".join(random.choices(string.ascii_lowercase, k=8))
    driver = create_smartproxy_driver(country=country, sticky_session=session_id)

    try:
        driver.get(url)
        time.sleep(3)

        sitekey = driver.execute_script(
            "return document.querySelector('[data-sitekey]')?.getAttribute('data-sitekey')"
        )

        if sitekey:
            token = solve_captcha(url, sitekey)
            driver.execute_script(f"""
                document.querySelector('#g-recaptcha-response').value = '{token}';
            """)
            driver.find_element(By.CSS_SELECTOR, "form").submit()
            time.sleep(3)

        return driver.page_source

    finally:
        driver.quit()

Tích hợp Node.js

const axios = require("axios");
const HttpsProxyAgent = require("https-proxy-agent");

const CAPTCHAAI_KEY = "YOUR_API_KEY";

function getSmartproxyAgent(options = {}) {
  let user = "spuser";
  if (options.country) user += `-country-${options.country}`;
  if (options.session) user += `-session-${options.session}`;

  return new HttpsProxyAgent(
    `http://${user}:sppassword@gate.smartproxy.com:10001`
  );
}

async function scrapeWithCaptcha(url, sitekey) {
  const agent = getSmartproxyAgent({
    country: "us",
    session: `sess-${Date.now()}`,
  });

  // Fetch page through proxy
  const pageResp = await axios.get(url, { httpsAgent: agent });

  // Solve CAPTCHA via CaptchaAI (no proxy needed)
  const submitResp = await axios.post(
    "https://ocr.captchaai.com/in.php",
    null,
    {
      params: {
        key: CAPTCHAAI_KEY,
        method: "userrecaptcha",
        googlekey: sitekey,
        pageurl: url,
        json: 1,
      },
    }
  );

  const taskId = submitResp.data.request;

  // Poll for result
  for (let i = 0; i < 60; i++) {
    await new Promise((r) => setTimeout(r, 5000));

    const result = await axios.get("https://ocr.captchaai.com/res.php", {
      params: {
        key: CAPTCHAAI_KEY,
        action: "get",
        id: taskId,
        json: 1,
      },
    });

    if (result.data.request === "CAPCHA_NOT_READY") continue;
    if (result.data.status === 1) return result.data.request;
  }

  throw new Error("Timeout");
}

Đường ống cạo đồng thời

from concurrent.futures import ThreadPoolExecutor, as_completed

def process_url(url):
    session_id = "".join(random.choices(string.ascii_lowercase, k=8))
    proxy = get_sticky_proxy(10)

    try:
        resp = requests.get(url, proxies=proxy, timeout=30)

        # Check if CAPTCHA is present (simplified detection)
        if "data-sitekey" in resp.text:
            import re
            match = re.search(r'data-sitekey="([^"]+)"', resp.text)
            if match:
                sitekey = match.group(1)
                token = solve_captcha(url, sitekey)
                return {"url": url, "status": "solved", "token": token[:30]}

        return {"url": url, "status": "no_captcha"}

    except Exception as e:
        return {"url": url, "status": "error", "error": str(e)}

urls = [
    "https://site1.com/page",
    "https://site2.com/page",
    "https://site3.com/page",
]

with ThreadPoolExecutor(max_workers=5) as executor:
    futures = {executor.submit(process_url, u): u for u in urls}

    for future in as_completed(futures):
        result = future.result()
        print(f"[{result['status']}] {result['url']}")

Khắc phục sự cố

Vấn đề Nguyên nhân Cách xử lý
Yêu cầu xác thực proxy 407 Định dạng tên người dùng/password sai Kiểm tra bảng điều khiển Smartproxy để biết thông tin xác thực
IP luân chuyển giữa phiên Không sử dụng phiên cố định Thêm -session-ID vào tên người dùng
CAPTCHA theo mọi yêu cầu Sử dụng điểm cuối của trung tâm dữ liệu Chuyển sang cổng dân cư
Kết nối chậm Mục tiêu địa lý bị tắc nghẽn Hãy thử quốc gia hoặc thành phố khác
Mã thông báo bị từ chối sau khi giải quyết IP đã thay đổi giữa tải và gửi Sử dụng thời lượng phiên cố định dài hơn

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

Tôi có thể chuyển IP Smartproxy cho CaptchaAI không?

Vâng. CaptchaAI chấp nhận tham số proxy trong yêu cầu gửi. Điều này làm cho CaptchaAI giải quyết được từ cùng một IP với trình duyệt của bạn.

Gói Smartproxy nào hoạt động tốt nhất cho quy trình làm việc của CAPTCHA?

Kế hoạch dân cư với các phiên dính. Trả tiền khi bạn di chuyển có hiệu quả về mặt chi phí đối với khối lượng vừa phải. Các gói doanh nghiệp cung cấp băng thông được đảm bảo.

Phiên cố định nên kéo dài bao lâu?

10 phút bao gồm hầu hết các quy trình công việc của CAPTCHA (tải trang †' giải quyết †' gửi). Kéo dài đến 30 phút cho các biểu mẫu nhiều bước.


Hướng dẫn liên quan


Ghép nối mạng dân cư của Smartproxy với CaptchaAI —lấy khóa API của bạnvà bắt đầu giải.

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