Skip to content

Commit 7c6b555

Browse files
committed
Repo-wide example repairs and QA
1 parent 8c4688e commit 7c6b555

927 files changed

Lines changed: 2183 additions & 85774 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

articles/abstract-captcha-solver-provider-agnostic/kotlin/solve.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,7 @@ fun main() {
9292
println(" Copy .env.example to .env and add your real API key.")
9393
exitProcess(1)
9494
}
95-
96-
// Submit — TODO: Change method and add CAPTCHA-specific parameters
95+
// Submit
9796
println("[*] Submitting reCAPTCHA v2 task...")
9897
val enc = java.nio.charset.StandardCharsets.UTF_8.name()
9998
val submitParams = "key=${URLEncoder.encode(apiKey, enc)}&method=userrecaptcha&googlekey=${URLEncoder.encode(googlekey, enc)}&pageurl=${URLEncoder.encode(pageurl, enc)}&json=1"

articles/abstract-captcha-solver-provider-agnostic/php/solve.php

Lines changed: 2 additions & 286 deletions
Original file line numberDiff line numberDiff line change
@@ -17,292 +17,8 @@
1717
define('RESULT_URL', 'https://ocr.captchaai.com/res.php');
1818

1919
$apiKey = $_ENV['CAPTCHAAI_API_KEY'] ?? '';
20-
$googlekey = <?php
21-
/**
22-
* Solve reCAPTCHA v2 using the CaptchaAI API.
23-
*
24-
* Usage:
25-
* composer install
26-
* cp ../.env.example ../.env # then edit with your credentials
27-
* php solve.php
28-
*/
29-
30-
require __DIR__ . '/vendor/autoload.php';
31-
32-
$dotenv = Dotenv\Dotenv::createImmutable(dirname(__DIR__));
33-
$dotenv->load();
34-
35-
define('SUBMIT_URL', 'https://ocr.captchaai.com/in.php');
36-
define('RESULT_URL', 'https://ocr.captchaai.com/res.php');
37-
38-
$apiKey = $_ENV['CAPTCHAAI_API_KEY'] ?? '';
39-
// TODO: Add CAPTCHA-specific environment variables here
40-
$pollInterval = (int)($_ENV['POLL_INTERVAL'] ?? 5);
41-
$maxTimeout = (int)($_ENV['MAX_TIMEOUT'] ?? 120);
42-
43-
$authErrors = ['ERROR_WRONG_USER_KEY', 'ERROR_KEY_DOES_NOT_EXIST', 'IP_BANNED'];
44-
$balanceErrors = ['ERROR_ZERO_BALANCE'];
45-
$inputErrors = ['ERROR_PAGEURL', 'ERROR_WRONG_GOOGLEKEY', 'ERROR_BAD_PARAMETERS', 'ERROR_BAD_TOKEN_OR_PAGEURL'];
46-
$transientErrors = ['ERROR_SERVER_ERROR', 'ERROR_INTERNAL_SERVER_ERROR'];
47-
$solveErrors = ['ERROR_CAPTCHA_UNSOLVABLE'];
48-
49-
// --- Validate configuration ---
50-
if (empty($apiKey) || $apiKey === 'YOUR_API_KEY') {
51-
echo "[!] ERROR: CAPTCHAAI_API_KEY is not set.\n";
52-
echo " Copy .env.example to .env and add your real API key.\n";
53-
exit(1);
54-
}
55-
56-
// --- Submit task ---
57-
echo "[*] Submitting reCAPTCHA v2 task...\n";
58-
$submitParams = http_build_query([
59-
'key' => $apiKey,
60-
'method' => 'userrecaptcha',
61-
'googlekey' => $googlekey,
62-
'pageurl' => $pageurl,
63-
'json' => '1',
64-
]);
65-
66-
$submitResponse = @file_get_contents(SUBMIT_URL . '?' . $submitParams);
67-
if ($submitResponse === false) {
68-
echo "[!] Network error during submission.\n";
69-
exit(1);
70-
}
71-
72-
$submitData = json_decode($submitResponse, true);
73-
if (($submitData['status'] ?? 0) !== 1) {
74-
$error = $submitData['request'] ?? 'UNKNOWN_ERROR';
75-
if (in_array($error, $authErrors)) {
76-
echo "[!] Authentication error: $error\n";
77-
echo " Check your API key at https://captchaai.com/dashboard\n";
78-
} elseif (in_array($error, $balanceErrors)) {
79-
echo "[!] Balance error: $error\n";
80-
echo " Top up your account at https://captchaai.com\n";
81-
} elseif (in_array($error, $inputErrors)) {
82-
echo "[!] Input error: $error\n";
83-
echo " Verify your sitekey and page URL are correct.\n";
84-
} else {
85-
echo "[!] Submission failed: $error\n";
86-
}
87-
exit(1);
88-
}
89-
90-
$taskId = $submitData['request'];
91-
echo "[+] Task submitted. ID: $taskId\n";
92-
93-
// --- Poll for result ---
94-
echo "[*] Waiting 15s before first poll...\n";
95-
sleep(15);
96-
97-
$elapsed = 15;
98-
$attempt = 0;
99-
$backoff = $pollInterval;
100-
101-
while ($elapsed < $maxTimeout) {
102-
$attempt++;
103-
echo "[*] Polling for result (attempt $attempt)...\n";
104-
105-
$resultParams = http_build_query([
106-
'key' => $apiKey,
107-
'action' => 'get',
108-
'id' => $taskId,
109-
'json' => '1',
110-
]);
111-
112-
$resultResponse = @file_get_contents(RESULT_URL . '?' . $resultParams);
113-
if ($resultResponse === false) {
114-
echo "[!] Network error during polling.\n";
115-
sleep($backoff);
116-
$elapsed += $backoff;
117-
$backoff = min($backoff * 2, 30);
118-
continue;
119-
}
120-
121-
$resultData = json_decode($resultResponse, true);
122-
123-
if (($resultData['status'] ?? 0) === 1) {
124-
$token = $resultData['request'];
125-
echo "[+] Solved! Token: " . substr($token, 0, 50) . "...\n";
126-
echo "[+] Full token length: " . strlen($token) . " characters\n";
127-
echo "\n";
128-
echo "Next step: inject this token into the target page's\n";
129-
echo "g-recaptcha-response hidden field and submit the form.\n";
130-
exit(0);
131-
}
132-
133-
$error = $resultData['request'] ?? '';
134-
if ($error === 'CAPCHA_NOT_READY') {
135-
echo "[*] Not ready yet, waiting {$pollInterval}s...\n";
136-
sleep($pollInterval);
137-
$elapsed += $pollInterval;
138-
$backoff = $pollInterval;
139-
continue;
140-
}
141-
142-
if (in_array($error, $transientErrors)) {
143-
echo "[!] Transient error: $error, retrying in {$backoff}s...\n";
144-
sleep($backoff);
145-
$elapsed += $backoff;
146-
$backoff = min($backoff * 2, 30);
147-
continue;
148-
}
149-
150-
if (in_array($error, $solveErrors)) {
151-
echo "[!] Solve error: $error\n";
152-
echo " The CAPTCHA could not be solved. Verify parameters and retry.\n";
153-
exit(1);
154-
}
155-
156-
echo "[!] Unexpected error: $error\n";
157-
exit(1);
158-
}
159-
160-
echo "[!] Timeout: no solution received within {$maxTimeout} seconds.\n";
161-
exit(1);
162-
ENV['CAPTCHA_GOOGLEKEY'] ?? '';
163-
$pageurl = <?php
164-
/**
165-
* Solve reCAPTCHA v2 using the CaptchaAI API.
166-
*
167-
* Usage:
168-
* composer install
169-
* cp ../.env.example ../.env # then edit with your credentials
170-
* php solve.php
171-
*/
172-
173-
require __DIR__ . '/vendor/autoload.php';
174-
175-
$dotenv = Dotenv\Dotenv::createImmutable(dirname(__DIR__));
176-
$dotenv->load();
177-
178-
define('SUBMIT_URL', 'https://ocr.captchaai.com/in.php');
179-
define('RESULT_URL', 'https://ocr.captchaai.com/res.php');
180-
181-
$apiKey = $_ENV['CAPTCHAAI_API_KEY'] ?? '';
182-
// TODO: Add CAPTCHA-specific environment variables here
183-
$pollInterval = (int)($_ENV['POLL_INTERVAL'] ?? 5);
184-
$maxTimeout = (int)($_ENV['MAX_TIMEOUT'] ?? 120);
185-
186-
$authErrors = ['ERROR_WRONG_USER_KEY', 'ERROR_KEY_DOES_NOT_EXIST', 'IP_BANNED'];
187-
$balanceErrors = ['ERROR_ZERO_BALANCE'];
188-
$inputErrors = ['ERROR_PAGEURL', 'ERROR_WRONG_GOOGLEKEY', 'ERROR_BAD_PARAMETERS', 'ERROR_BAD_TOKEN_OR_PAGEURL'];
189-
$transientErrors = ['ERROR_SERVER_ERROR', 'ERROR_INTERNAL_SERVER_ERROR'];
190-
$solveErrors = ['ERROR_CAPTCHA_UNSOLVABLE'];
191-
192-
// --- Validate configuration ---
193-
if (empty($apiKey) || $apiKey === 'YOUR_API_KEY') {
194-
echo "[!] ERROR: CAPTCHAAI_API_KEY is not set.\n";
195-
echo " Copy .env.example to .env and add your real API key.\n";
196-
exit(1);
197-
}
198-
199-
// --- Submit task ---
200-
echo "[*] Submitting reCAPTCHA v2 task...\n";
201-
$submitParams = http_build_query([
202-
'key' => $apiKey,
203-
'method' => 'userrecaptcha',
204-
'googlekey' => $googlekey,
205-
'pageurl' => $pageurl,
206-
'json' => '1',
207-
]);
208-
209-
$submitResponse = @file_get_contents(SUBMIT_URL . '?' . $submitParams);
210-
if ($submitResponse === false) {
211-
echo "[!] Network error during submission.\n";
212-
exit(1);
213-
}
214-
215-
$submitData = json_decode($submitResponse, true);
216-
if (($submitData['status'] ?? 0) !== 1) {
217-
$error = $submitData['request'] ?? 'UNKNOWN_ERROR';
218-
if (in_array($error, $authErrors)) {
219-
echo "[!] Authentication error: $error\n";
220-
echo " Check your API key at https://captchaai.com/dashboard\n";
221-
} elseif (in_array($error, $balanceErrors)) {
222-
echo "[!] Balance error: $error\n";
223-
echo " Top up your account at https://captchaai.com\n";
224-
} elseif (in_array($error, $inputErrors)) {
225-
echo "[!] Input error: $error\n";
226-
echo " Verify your sitekey and page URL are correct.\n";
227-
} else {
228-
echo "[!] Submission failed: $error\n";
229-
}
230-
exit(1);
231-
}
232-
233-
$taskId = $submitData['request'];
234-
echo "[+] Task submitted. ID: $taskId\n";
235-
236-
// --- Poll for result ---
237-
echo "[*] Waiting 15s before first poll...\n";
238-
sleep(15);
239-
240-
$elapsed = 15;
241-
$attempt = 0;
242-
$backoff = $pollInterval;
243-
244-
while ($elapsed < $maxTimeout) {
245-
$attempt++;
246-
echo "[*] Polling for result (attempt $attempt)...\n";
247-
248-
$resultParams = http_build_query([
249-
'key' => $apiKey,
250-
'action' => 'get',
251-
'id' => $taskId,
252-
'json' => '1',
253-
]);
254-
255-
$resultResponse = @file_get_contents(RESULT_URL . '?' . $resultParams);
256-
if ($resultResponse === false) {
257-
echo "[!] Network error during polling.\n";
258-
sleep($backoff);
259-
$elapsed += $backoff;
260-
$backoff = min($backoff * 2, 30);
261-
continue;
262-
}
263-
264-
$resultData = json_decode($resultResponse, true);
265-
266-
if (($resultData['status'] ?? 0) === 1) {
267-
$token = $resultData['request'];
268-
echo "[+] Solved! Token: " . substr($token, 0, 50) . "...\n";
269-
echo "[+] Full token length: " . strlen($token) . " characters\n";
270-
echo "\n";
271-
echo "Next step: inject this token into the target page's\n";
272-
echo "g-recaptcha-response hidden field and submit the form.\n";
273-
exit(0);
274-
}
275-
276-
$error = $resultData['request'] ?? '';
277-
if ($error === 'CAPCHA_NOT_READY') {
278-
echo "[*] Not ready yet, waiting {$pollInterval}s...\n";
279-
sleep($pollInterval);
280-
$elapsed += $pollInterval;
281-
$backoff = $pollInterval;
282-
continue;
283-
}
284-
285-
if (in_array($error, $transientErrors)) {
286-
echo "[!] Transient error: $error, retrying in {$backoff}s...\n";
287-
sleep($backoff);
288-
$elapsed += $backoff;
289-
$backoff = min($backoff * 2, 30);
290-
continue;
291-
}
292-
293-
if (in_array($error, $solveErrors)) {
294-
echo "[!] Solve error: $error\n";
295-
echo " The CAPTCHA could not be solved. Verify parameters and retry.\n";
296-
exit(1);
297-
}
298-
299-
echo "[!] Unexpected error: $error\n";
300-
exit(1);
301-
}
302-
303-
echo "[!] Timeout: no solution received within {$maxTimeout} seconds.\n";
304-
exit(1);
305-
ENV['CAPTCHA_PAGEURL'] ?? '';
20+
$googlekey = $_ENV['CAPTCHA_GOOGLEKEY'] ?? '';
21+
$pageurl = $_ENV['CAPTCHA_PAGEURL'] ?? '';
30622
$pollInterval = (int)($_ENV['POLL_INTERVAL'] ?? 5);
30723
$maxTimeout = (int)($_ENV['MAX_TIMEOUT'] ?? 120);
30824

articles/abstract-captcha-solver-provider-agnostic/rust/src/main.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ fn main() {
7373
}
7474

7575
// Submit
76+
println!("[*] Submitting reCAPTCHA v2 task...");
7677
let submit_url = format!(
7778
"https://ocr.captchaai.com/in.php?key={}&method=userrecaptcha&googlekey={}&pageurl={}&json=1",
7879
urlencoding::encode(&api_key), urlencoding::encode(&googlekey), urlencoding::encode(&pageurl)
@@ -165,4 +166,4 @@ fn main() {
165166

166167
println!("[!] Timeout: no solution received within {} seconds.", max_timeout);
167168
std::process::exit(1);
168-
}
169+
}

articles/academic-research-scraping-captcha-solving/kotlin/solve.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,7 @@ fun main() {
9292
println(" Copy .env.example to .env and add your real API key.")
9393
exitProcess(1)
9494
}
95-
96-
// Submit — TODO: Change method and add CAPTCHA-specific parameters
95+
// Submit
9796
println("[*] Submitting reCAPTCHA v2 task...")
9897
val enc = java.nio.charset.StandardCharsets.UTF_8.name()
9998
val submitParams = "key=${URLEncoder.encode(apiKey, enc)}&method=userrecaptcha&googlekey=${URLEncoder.encode(googlekey, enc)}&pageurl=${URLEncoder.encode(pageurl, enc)}&json=1"

0 commit comments

Comments
 (0)