-
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.42 KB
/
main.js
File metadata and controls
77 lines (62 loc) · 2.42 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';
// Configuracion de la API de CapSolver
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';
// Configuracion del sitio web objetivo (pagina de demostracion de Google reCAPTCHA)
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(`Error al crear la tarea: ${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(`Error al obtener el resultado: ${result.errorDescription}`);
}
if (result.status === 'ready') {
return result.solution;
} else if (result.status === 'processing') {
console.log('La tarea aun se esta procesando, esperando...');
await new Promise(resolve => setTimeout(resolve, 2000));
} else {
throw new Error(`Estado desconocido: ${result.status}`);
}
}
}
async function main() {
if (!CAPSOLVER_API_KEY) {
console.log('Error: CAPSOLVER_API_KEY no encontrada en el archivo .env');
console.log('Por favor, crea un archivo .env con tu clave API:');
console.log('CAPSOLVER_API_KEY=tu_clave_api_aqui');
return;
}
console.log('Creando tarea de resolucion de ReCaptcha V2...');
const taskId = await createTask();
console.log(`Tarea creada exitosamente! ID de tarea: ${taskId}`);
console.log('Esperando la solucion...');
const solution = await getTaskResult(taskId);
console.log('\nSolucion recibida!');
console.log(`gRecaptchaResponse: ${solution.gRecaptchaResponse.substring(0, 100)}...`);
}
main().catch(console.error);