반환된 사용자 에이전트와 클라이언트 힌트 사용하기
대상 웹사이트에 솔루션을 제출하는 요청에 반환된 브라우저 식별 정보를 사용하세요. 솔루션의 값으로 두 헤더를 모두 설정하고 해결 과정에서 성공한 프록시를 통해 요청을 보내세요.
이 페이지의 내용
기존 브라우저 헤더 교체
| HTTP 헤더 | 준비된 솔루션의 값 |
|---|---|
| User-Agent | solution.userAgent |
| sec-ch-ua | solution.secChUa |
스크레이퍼나 기존 HTTP 세션의 임의 사용자 에이전트를 그대로 사용하지 마세요. 그러면 솔루션과 함께 반환된 브라우저 식별 정보를 관련 없는 정보로 대체하게 됩니다. sec-ch-ua만 업데이트하면 두 헤더가 서로 다른 브라우저를 나타내게 됩니다.
중복 헤더를 추가하지 말고 기존 값을 교체하세요. 요청을 보내기 전에 값을 덮어쓸 수 있는 세션 기본값이나 요청 생성 미들웨어를 확인하세요.
성공한 프록시 사용
ready 결과에서 시작하세요. pending과 solving에는 사용 가능한 솔루션이 없습니다. SDK의 solve 메서드는 준비된 결과가 나올 때까지 기다리거나 오류를 발생시킵니다.
단일 proxy로 제출한 작업은 대상 요청에도 해당 프록시를 재사용하세요. proxyCandidates를 제공했다면 Python의 successful_proxy(original_task, ready_result) 또는 JavaScript의 successfulProxy(originalTask, readyResult)로 성공한 프록시를 선택하세요. 단순히 첫 번째 후보를 사용하지 마세요.
아래 예제는 request의 proxy 필드에서 전송용 프록시를 읽습니다. 후보 기반 작업의 경우 요청을 보내기 전에 도우미가 선택한 값을 해당 필드에 넣으세요. 설정 방법은 프록시 후보 선택을 참조하세요.
Python 또는 Node.js에서 대상 요청 전송
이 예제들은 reCAPTCHA v3 Enterprise 토큰을 제출합니다. Python에서 solution은 준비된 결과의 솔루션 딕셔너리입니다. Node.js에서 result는 준비된 작업입니다. 두 예제 모두 반환된 헤더를 명시적으로 설정하고 선택한 프록시를 통해 요청을 전송합니다.
# Continue after client.solve(). Install requests separately: pip install requests.
import requests
# This example endpoint accepts the standard reCAPTCHA form field.
# Use your application's real URL, form fields, CSRF token and session.
response = requests.post(
"https://accounts.example.com/login",
data={"g-recaptcha-response": solution["token"]},
headers={
"User-Agent": solution["userAgent"],
"sec-ch-ua": solution["secChUa"],
},
proxies={"http": request["proxy"], "https": request["proxy"]},
timeout=30,
allow_redirects=False,
)
# Inspect the application's response to determine whether it accepted the request.
print("Application HTTP status:", response.status_code)// Continue after client.solve(). Install undici separately: npm install undici@7.
import { fetch, ProxyAgent } from 'undici';
const dispatcher = new ProxyAgent(request.proxy);
try {
// Replace the URL and form fields with your application's contract.
const response = await fetch('https://accounts.example.com/login', {
method: 'POST',
dispatcher,
redirect: 'manual',
headers: {
'user-agent': result.solution.userAgent,
'sec-ch-ua': result.solution.secChUa,
},
body: new URLSearchParams({
'g-recaptcha-response': result.solution.token,
}),
signal: AbortSignal.timeout(30_000),
});
console.log('Application HTTP status:', response.status);
await response.arrayBuffer();
} finally {
await dispatcher.close();
}예제의 로그인 URL을 의도한 대상 URL로 바꾸고 해당 애플리케이션의 실제 폼 필드, CSRF 토큰, 세션을 사용하세요. 예제는 애플리케이션이 g-recaptcha-response로 토큰을 받는다고 가정합니다. 반환된 브라우저 헤더는 폼 본문이 아닌 HTTP 헤더에 넣어야 합니다.
대상이 요청을 거부하면 HTTP 클라이언트가 실제로 전송한 토큰 값, 두 브라우저 헤더, 프록시, 목적지 URL을 확인하세요. 작업이 ready라는 것은 솔루션이 생성되었다는 뜻이지, 대상이 제출을 수락했다는 뜻은 아닙니다. 출력된 애플리케이션 HTTP 상태를 출발점으로 삼되, 실제 성공 또는 실패 결과는 애플리케이션 응답에서 확인하세요.
첫 작업을 실행하세요.
워크스페이스 크레딧 $5로 시작하세요.