-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbatch_processing.py
More file actions
58 lines (46 loc) · 1.78 KB
/
batch_processing.py
File metadata and controls
58 lines (46 loc) · 1.78 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
"""
Example: Batch Process Multiple CAPTCHAs
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This example shows how to solve multiple CAPTCHA images in batch.
"""
from fastcaptcha import FastCaptcha
import glob
import time
def main():
# Initialize the solver
api_key = "your-api-key-here" # Replace with your actual API key
# Use context manager for automatic session cleanup
with FastCaptcha(api_key=api_key) as solver:
# Find all CAPTCHA images in a directory
captcha_files = glob.glob("captchas/*.jpg")
if not captcha_files:
print("No CAPTCHA images found in 'captchas/' directory")
return
print(f"Found {len(captcha_files)} CAPTCHAs to solve\n")
# Track statistics
successful = 0
failed = 0
start_time = time.time()
# Process each CAPTCHA
for i, captcha_file in enumerate(captcha_files, 1):
try:
print(f"[{i}/{len(captcha_files)}] Solving {captcha_file}...", end=" ")
result = solver.solve(captcha_file)
print(f"✓ Result: {result}")
successful += 1
except Exception as e:
print(f"✗ Error: {e}")
failed += 1
# Print statistics
elapsed = time.time() - start_time
print(f"\n{'='*50}")
print(f"Batch Processing Complete")
print(f"{'='*50}")
print(f"Total: {len(captcha_files)}")
print(f"Successful: {successful}")
print(f"Failed: {failed}")
print(f"Time elapsed: {elapsed:.2f} seconds")
print(f"Average time per CAPTCHA: {elapsed/len(captcha_files):.2f} seconds")
print(f"{'='*50}")
if __name__ == "__main__":
main()