-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathyandex_smartcaptcha.js
More file actions
55 lines (48 loc) · 1.98 KB
/
Copy pathyandex_smartcaptcha.js
File metadata and controls
55 lines (48 loc) · 1.98 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
/**
* Example: Solve a Yandex SmartCaptcha challenge (token-based).
*
* Prerequisites:
* Set the CAPTCHA_API_KEY environment variable.
* Replace websiteURL and websiteKey with values from your target page.
*/
import 'dotenv/config';
import { CaptchaClient, Tasks } from '@captcha-solver-api/javascript-sdk';
const apiKey = process.env.CAPTCHA_API_KEY || 'YOUR_API_KEY';
const captchaSolver = new CaptchaClient({ clientKey: apiKey });
// --- Proxyless example ---
// The service's own proxies are used to solve the captcha.
// websiteKey is the sitekey value from the page code or captcha iframe.
const proxylessTask = new Tasks.YandexSmartCaptchaTaskProxyless({
websiteURL: 'https://example.com/login', // Full URL of the page with captcha
websiteKey: 'FEXfAbHQsToo97VidNVk3j4dC74nGW1DgdxK4OoR' // sitekey from page code or iframe
// Optional fields:
// userAgent: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) ...',
// cookies: 'session=abc123; token=xyz789',
});
captchaSolver.solve(proxylessTask)
.then((result) => {
// Solution contains { token: "dV9xNjYyNTU3NjkxO4k9OTQuNVMuMjkuMjM9..." }
console.log('result:', result);
})
.catch((error) => {
console.error(error);
});
// --- With proxy example ---
// Note: this is the only captcha type where an https proxy is accepted.
const proxyTask = new Tasks.YandexSmartCaptchaTask({
websiteURL: 'https://example.com/login',
websiteKey: 'FEXfAbHQsToo97VidNVk3j4dC74nGW1DgdxK4OoR',
// --- Proxy parameters ---
proxyType: 'http', // http, https, socks4, or socks5 (https is accepted only for this type)
proxyAddress: '1.2.3.4', // Proxy IP address
proxyPort: 8080, // Proxy port
proxyLogin: 'user', // Login for proxy authorization (optional)
proxyPassword: 'password' // Password for proxy authorization (optional)
});
captchaSolver.solve(proxyTask)
.then((result) => {
console.log('result:', result);
})
.catch((error) => {
console.error(error);
});