-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
82 lines (65 loc) · 2.39 KB
/
main.js
File metadata and controls
82 lines (65 loc) · 2.39 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
78
79
80
81
82
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
// Replace with your target site values
const SITE_URL = 'https://example.com';
const SITE_KEY = 'MTPublic-xxxxxxxxx'; // Format: MTPublic-xxx
async function createTask() {
const payload = {
clientKey: CAPSOLVER_API_KEY,
task: {
type: 'MtCaptchaTaskProxyLess',
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 MtCaptcha solving task...');
console.log(`Site Key: ${SITE_KEY}`);
const taskId = await createTask();
console.log(`Task created successfully! Task ID: ${taskId}`);
console.log('Waiting for solution (5-30 seconds)...');
const solution = await getTaskResult(taskId);
console.log('\nSolution received!');
console.log(`Token: ${solution.token}`);
// Use this token in your target website form submission
}
main().catch(console.error);