-
Notifications
You must be signed in to change notification settings - Fork 0
/
turnstile-captcha-solving-nodejs
66 lines (58 loc) · 1.97 KB
/
turnstile-captcha-solving-nodejs
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
const axios = require('axios');
const CAPSOLVER_API_KEY = "";
const PAGE_URL = "https://peet.ws/turnstile-test/non-interactive.html";
const WEBSITE_KEY = "0x4AAAAAAABS7vwvV6VFfMcD";
async function solvecf(metadata_action = null, metadata_cdata = null) {
const url = "https://api.capsolver.com/createTask";
const task = {
type: "AntiTurnstileTaskProxyLess",
websiteURL: PAGE_URL,
websiteKey: WEBSITE_KEY,
};
if (metadata_action || metadata_cdata) {
task.metadata = {};
if (metadata_action) {
task.metadata.action = metadata_action;
}
if (metadata_cdata) {
task.metadata.cdata = metadata_cdata;
}
}
const data = {
clientKey: CAPSOLVER_API_KEY,
task: task
};
const response = await axios.post(url, data);
console.log(response.data);
return response.data.taskId;
}
async function solutionGet(taskId) {
const url = "https://api.capsolver.com/getTaskResult";
let status = "";
while (status !== "ready") {
const data = { clientKey: CAPSOLVER_API_KEY, taskId: taskId };
const response = await axios.post(url, data);
console.log(response.data);
status = response.data.status;
console.log(status);
if (status === "ready") {
return response.data.solution;
}
await new Promise(resolve => setTimeout(resolve, 2000));
}
}
async function main() {
const start_time = Date.now();
const taskId = await solvecf();
const solution = await solutionGet(taskId);
if (solution) {
const user_agent = solution.userAgent;
const token = solution.token;
console.log("User_Agent:", user_agent);
console.log("Solved Turnstile Captcha, token:", token);
}
const end_time = Date.now();
const elapsed_time = (end_time - start_time) / 1000;
console.log(`Time to solve the captcha: ${elapsed_time} seconds`);
}
main().catch(console.error);