These automate a real browser to interact with and solve CAPTCHAs on a live web page.
To distribute this GitHub project as a portable application that runs on machines without Python, compile it into a single folder or executable using PyInstaller. Install PyInstaller in your development environment: pip install pyinstaller Use code with caution. Compile the script into a single portable directory: pyinstaller --onedir --clean main.py Use code with caution.
Install the core libraries directly into your local environment: pip install ddddocr opencv-python pillow pyinstaller Use code with caution. Developing the Python CAPTCHA Solver
The trade-off for portability is usually . Simple OCR fails on:
To ensure portability, consider the following:
mkdir portable_captcha_solver cd portable_captcha_solver python -m venv venv Use code with caution. Step 2: Activate the Environment Activate the environment locally: venv\Scripts\activate Linux/macOS: source venv/bin/activate Step 3: Install Required Packages
import os import sys # Force Python to look into our local lib folder for dependencies sys.path.append(os.path.join(os.path.dirname(__file__), '..', 'lib')) import ddddocr class PortableCaptchaSolver: def __init__(self): # Initialize the classification engine silently self.ocr = ddddocr.DdddOcr(show_ad=False) def solve_image_captcha(self, image_path): """Solves standard alphanumeric image CAPTCHAs.""" if not os.path.exists(image_path): return "Error: Image file not found." with open(image_path, 'rb') as f: image_bytes = f.read() # Extract text from image bytes result = self.ocr.classification(image_bytes) return result def solve_slide_captcha(self, target_path, background_path): """Finds the horizontal offset for slider puzzles.""" with open(target_path, 'rb') as f: target_bytes = f.read() with open(background_path, 'rb') as f: bg_bytes = f.read() result = self.ocr.slide_match(target_bytes, bg_bytes) # Returns a dictionary containing coordinates like 'target': [x1, y1, x2, y2] return result.get('target', [0])[0] Use code with caution. Step 3: Integrating the Automation Framework ( src/main.py )
A highly popular, lightweight, pre-trained optical character recognition anti-CAPTCHA tool. It requires no external engine installations (like Tesseract) and excels at alphanumeric images, sliding puzzles, and click-on-character verifications.
Keep your temporary storage bound strictly to your project folder. Avoid writing logs or downloading temporary screen assets to global paths like C:\Users\Username\AppData .
portable-captcha-solver/ │ ├── python_embed/ # The extracted Python embeddable zip │ ├── python.exe │ └── ... ├── src/ │ ├── main.py # Main automation script │ └── solver.py # CAPTCHA solving logic ├── lib/ # Locally installed site-packages ├── run.bat # Windows batch file to trigger execution └── requirements.txt # List of dependencies Use code with caution. Step 1: Setting Up the Portable Python Core
The best choice depends on your specific requirements: