-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
77 lines (62 loc) · 2.33 KB
/
main.js
File metadata and controls
77 lines (62 loc) · 2.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import 'dotenv/config';
import axios from 'axios';
// CapSolver API configuration
const CAPSOLVER_API_KEY = process.env.CAPSOLVER_API_KEY;
const CREATE_TASK_URL = 'https://api.capsolver.com/createTask';
const GET_RESULT_URL = 'https://api.capsolver.com/getTaskResult';
// Target website configuration (Google reCAPTCHA demo page)
const SITE_URL = 'https://www.google.com/recaptcha/api2/demo';
const SITE_KEY = '6Le-wvkSAAAAAPBMRTvw0Q4Muexq9bi0DJwx_mJ-';
async function createTask() {
const payload = {
clientKey: CAPSOLVER_API_KEY,
task: {
type: 'ReCaptchaV2TaskProxyLess',
websiteURL: SITE_URL,
websiteKey: SITE_KEY
}
};
const response = await axios.post(CREATE_TASK_URL, payload);
const result = response.data;
if (result.errorId !== 0) {
throw new Error(`Failed to create task: ${result.errorDescription}`);
}
return result.taskId;
}
async function getTaskResult(taskId) {
const payload = {
clientKey: CAPSOLVER_API_KEY,
taskId: taskId
};
while (true) {
const response = await axios.post(GET_RESULT_URL, payload);
const result = response.data;
if (result.errorId !== 0) {
throw new Error(`Failed to get result: ${result.errorDescription}`);
}
if (result.status === 'ready') {
return result.solution;
} else if (result.status === 'processing') {
console.log('Task is still processing, waiting...');
await new Promise(resolve => setTimeout(resolve, 2000));
} else {
throw new Error(`Unknown status: ${result.status}`);
}
}
}
async function main() {
if (!CAPSOLVER_API_KEY) {
console.log('Error: CAPSOLVER_API_KEY not found in .env file');
console.log('Please create a .env file with your API key:');
console.log('CAPSOLVER_API_KEY=your_api_key_here');
return;
}
console.log('Creating ReCaptcha V2 solving task...');
const taskId = await createTask();
console.log(`Task created successfully! Task ID: ${taskId}`);
console.log('Waiting for solution...');
const solution = await getTaskResult(taskId);
console.log('\nSolution received!');
console.log(`gRecaptchaResponse: ${solution.gRecaptchaResponse.substring(0, 100)}...`);
}
main().catch(console.error);