-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcaptcha-example.js
More file actions
123 lines (105 loc) · 3.22 KB
/
Copy pathcaptcha-example.js
File metadata and controls
123 lines (105 loc) · 3.22 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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/**
* Scrapeless Node SDK - Captcha Service Example (ES Module Version)
*/
import { ScrapelessClient } from '@scrapeless-ai/sdk';
// Initialize client
const client = new ScrapelessClient({
apiKey: process.env.SCRAPELESS_API_KEY || 'your_api_key_here'
});
/**
* Test reCAPTCHA solving
*/
async function testRecaptcha() {
try {
console.log('Testing reCAPTCHA solving...');
const result = await client.captcha.captchaSolver({
actor: 'captcha.recaptcha',
input: {
version: 'v2',
pageURL: 'https://www.google.com',
siteKey: '6Le-wvkSAAAAAPBMRTvw0Q4Muexq9bi0DJwx_mJ-',
pageAction: 'scraping',
invisible: false
}
});
console.log('✅ reCAPTCHA solving successful');
console.log('Result:', JSON.stringify(result, null, 2));
return result;
} catch (error) {
console.error('❌ reCAPTCHA solving failed:', error.message);
throw error;
}
}
/**
* Test hCaptcha solving
*/
async function testHcaptcha() {
try {
console.log('Testing hCaptcha solving...');
const result = await client.captcha.captchaSolver({
actor: 'captcha.hcaptcha',
input: {
sitekey: '10000000-ffff-ffff-ffff-000000000001', // Test site key
url: 'https://hcaptcha.com/playground'
}
});
console.log('✅ hCaptcha solving successful');
console.log('Result:', JSON.stringify(result, null, 2));
return result;
} catch (error) {
console.error('❌ hCaptcha solving failed:', error.message);
throw error;
}
}
/**
* Test captcha task creation and status checking
*/
async function testTaskCreationAndStatus() {
try {
console.log('Testing captcha task creation...');
const task = await client.captcha.captchaCreate({
actor: 'captcha.hcaptcha',
input: {
sitekey: '6LeIxAcTAAAAAJcZVRqyHh71UMIEGNQ_MXjiZKhI',
url: 'https://recaptcha-demo.appspot.com'
}
});
console.log('✅ Task creation successful:', task.data.taskId);
// Wait 5 seconds before checking status
await new Promise(resolve => setTimeout(resolve, 5000));
console.log('Testing captcha task status check...');
const status = await client.captcha.captchaResultGet(task.data.taskId);
console.log('✅ Task status check successful');
console.log('Status:', JSON.stringify(status.data, null, 2));
return { task: task.data, status: status.data };
} catch (error) {
console.error('❌ Task creation or status check failed:', error.message);
throw error;
}
}
/**
* Run all tests
*/
async function runTests() {
console.log('=== Scrapeless Captcha Service Tests ===\n');
try {
// Test reCAPTCHA
await testRecaptcha();
console.log('\n');
// Test hCaptcha
await testHcaptcha();
console.log('\n');
// Test task creation and status
await testTaskCreationAndStatus();
console.log('\n');
console.log('🎉 All tests completed');
} catch (error) {
console.error('❌ Error occurred during testing:', error);
}
}
// Run tests
runTests().catch(console.error);
// If you need to run specific tests individually, uncomment the code below
// testRecaptcha().catch(console.error);
// testHcaptcha().catch(console.error);
// testTaskCreationAndStatus().catch(console.error);