### Install Playwright Captcha Source: https://github.com/techinz/playwright-captcha/blob/main/README.md Install the playwright-captcha package using pip. ```bash pip install playwright-captcha ``` -------------------------------- ### API Solver Example (TwoCaptcha) Source: https://github.com/techinz/playwright-captcha/blob/main/README.md Shows how to integrate TwoCaptchaSolver for solving captchas via the 2Captcha.com API. Requires setting the TWO_CAPTCHA_API_KEY environment variable and initializing the AsyncTwoCaptcha client. ```python import asyncio import os from playwright.async_api import async_playwright from twocaptcha import AsyncTwoCaptcha from playwright_captcha import CaptchaType, TwoCaptchaSolver, FrameworkType async def solve_with_2captcha(): # Initialize 2Captcha client captcha_client = AsyncTwoCaptcha(os.getenv('TWO_CAPTCHA_API_KEY')) async with async_playwright() as playwright: browser = await playwright.chromium.launch(headless=False) page = await browser.new_page() framework = FrameworkType.PLAYWRIGHT # Create solver before navigating to the page # Available API Solvers: # TwoCaptchaSolver # TenCaptchaSolver async with TwoCaptchaSolver(framework=framework, page=page, async_two_captcha_client=captcha_client) as solver: # Navigate to your target page await page.goto('https://example.com/with-recaptcha') # Solve reCAPTCHA v2 await solver.solve_captcha( captcha_container=page, captcha_type=CaptchaType.RECAPTCHA_V2 ) # Continue with your automation... asyncio.run(solve_with_2captcha()) ``` -------------------------------- ### Project Structure Source: https://github.com/techinz/playwright-captcha/blob/main/README.md Illustrates the directory layout of the playwright-captcha project, highlighting example usage and package components. ```tree playwright-captcha/ ├── examples/ # Usage examples │ ├── cloudflare/ # Cloudflare captcha examples │ └── recaptcha/ # reCAPTCHA examples └── playwright_captcha/ # Main package ├── captchas/ # Captcha type implementations ├── solvers/ # Solver implementations ├── types/ # Type definitions └── utils/ # Utility functions ``` -------------------------------- ### Click Solver Example Source: https://github.com/techinz/playwright-captcha/blob/main/README.md Demonstrates how to use the ClickSolver to automatically click and solve captchas directly within the browser using Playwright. Ensure Playwright is launched with stealthy patches for better results. ```python import asyncio from playwright.async_api import async_playwright from playwright_captcha import CaptchaType, ClickSolver, FrameworkType async def solve_captcha(): async with async_playwright() as playwright: browser = await playwright.chromium.launch(headless=True) page = await browser.new_page() framework = FrameworkType.PLAYWRIGHT # Create solver before navigating to the page async with ClickSolver(framework=framework, page=page) as solver: # Navigate to your target page await page.goto('https://example.com/with-captcha') # Solve the captcha await solver.solve_captcha( captcha_container=page, captcha_type=CaptchaType.CLOUDFLARE_TURNSTILE ) # Continue with your automation... asyncio.run(solve_captcha()) ``` -------------------------------- ### Launch Playwright with Patchright Source: https://github.com/techinz/playwright-captcha/blob/main/README.md Launches a Chromium browser using Patchright for stealth capabilities. Use this when you need to bypass detection mechanisms that standard Playwright might trigger. ```python from patchright.async_api import async_playwright from playwright_captcha import FrameworkType async with async_playwright() as playwright: browser = await playwright.chromium.launch(channel="chrome", headless=False) framework = FrameworkType.PATCHRIGHT # ... rest of your code ``` -------------------------------- ### TwoCaptcha Solver Configuration Source: https://github.com/techinz/playwright-captcha/blob/main/README.md Configures a TwoCaptchaSolver with custom settings, including an asynchronous client and optional sitekey. Useful when automatic detection fails. ```python # API solver with custom settings (TwoCaptcha) solver = TwoCaptchaSolver( framework=framework, # Framework type (PLAYWRIGHT, PATCHRIGHT, CAMOUFOX) page=page, async_two_captcha_client=captcha_client, max_attempts=3, attempt_delay=10, # also you can specify the captcha data like sitekey manually if it fails to detect automatically sitekey='sitekey' # ... ) ``` -------------------------------- ### Environment Variables for API Keys Source: https://github.com/techinz/playwright-captcha/blob/main/README.md Defines environment variables for API keys required by captcha solving services. Create a .env file to manage these keys. ```env TWO_CAPTCHA_API_KEY=your_2captcha_api_key_here TEN_CAPTCHA_API_KEY=your_10captcha_api_key_here ``` -------------------------------- ### Click Solver Configuration Source: https://github.com/techinz/playwright-captcha/blob/main/README.md Configures a ClickSolver with custom settings for solving captchas. Specify the framework, page object, maximum attempts, and delay between attempts. ```python # Click solver with custom settings solver = ClickSolver( framework=framework, # Framework type (PLAYWRIGHT, PATCHRIGHT, CAMOUFOX) page=page, max_attempts=5, # Number of solving attempts attempt_delay=3 # Delay between attempts (seconds) ) ``` -------------------------------- ### Launch Playwright with Camoufox Source: https://github.com/techinz/playwright-captcha/blob/main/README.md Launches a browser with Camoufox, a stealth browser extension, for enhanced anonymity and captcha solving. It requires specific addons and configurations for human-like behavior. ```python from camoufox import AsyncCamoufox from playwright_captcha.utils.camoufox_add_init_script.add_init_script import get_addon_path from playwright_captcha import FrameworkType import os ADDON_PATH = get_addon_path() async with AsyncCamoufox( headless=False, geoip=True, humanize=True, main_world_eval=True, # add this addons=[os.path.abspath(ADDON_PATH)] # add this ) as browser: context = await browser.new_context() page = await context.new_page() framework = FrameworkType.CAMOUFOX # ... rest of your code ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.