### Install Example Requirements Source: https://github.com/alperensert/capmonster_python/wiki/4.-Examples-and-Tests Installs the necessary Python packages for running the examples. ```bash cd examples pip install -r requirements.txt ``` -------------------------------- ### Run a Recaptcha V2 Selenium Example Source: https://github.com/alperensert/capmonster_python/wiki/4.-Examples-and-Tests Executes a Python script to solve a Recaptcha V2 using Selenium. Ensure Firefox is installed and API_KEY/HEADLESS environment variables are set. ```bash python recaptchav2_selenium.py ``` -------------------------------- ### Install capmonster_python with pipx Source: https://github.com/alperensert/capmonster_python/blob/master/docs/installation.md Use this command to install the latest version of capmonster_python using pipx. ```bash pipx install capmonster_python ``` -------------------------------- ### Install legacy v3 syntax of capmonster-python Source: https://github.com/alperensert/capmonster_python/blob/master/docs/installation.md Install version 3.2 of capmonster-python if you need to use the legacy v3 syntax. ```bash pip install capmonster-python==3.2 ``` -------------------------------- ### Solve DataDome Challenge (Async) Source: https://github.com/alperensert/capmonster_python/blob/master/docs/examples.md This asynchronous example demonstrates how to solve DataDome challenges. You will need the website URL, the DataDome cookie, and the CAPTCHA URL. ```python import asyncio from capmonster_python import CapmonsterClient, DataDomeTask, DataDomeMetadata async def main(): client = CapmonsterClient(api_key="") task = DataDomeTask( websiteURL="https://example.com", metadata=DataDomeMetadata( datadomeCookie="datadome=...", captchaUrl="https://captcha-url" ) ) task_id = await client.create_task_async(task) result = await client.get_task_result_async(task_id) print(result) asyncio.run(main()) ``` -------------------------------- ### Solve DataDome Challenge (Sync) Source: https://github.com/alperensert/capmonster_python/blob/master/docs/examples.md This synchronous example demonstrates how to solve DataDome challenges. You will need the website URL, the DataDome cookie, and the CAPTCHA URL. ```python from capmonster_python import CapmonsterClient, DataDomeTask, DataDomeMetadata client = CapmonsterClient(api_key="") task_id = client.create_task(DataDomeTask( websiteURL="https://example.com", metadata=DataDomeMetadata( datadomeCookie="datadome=...", captchaUrl="https://captcha-url" ) )) result = client.get_task_result(task_id) print(result) ``` -------------------------------- ### Get Account Balance (Sync) Source: https://github.com/alperensert/capmonster_python/blob/master/docs/reference/client.md Fetches the current account balance. Returns 0.0 if the balance cannot be determined. ```python def get_balance(self) -> float ``` -------------------------------- ### Install capmonster_python with pip Source: https://github.com/alperensert/capmonster_python/blob/master/docs/installation.md Use this command to install the latest version of capmonster_python using pip. ```bash pip install capmonster_python ``` -------------------------------- ### Install capmonster_python with poetry Source: https://github.com/alperensert/capmonster_python/blob/master/docs/installation.md Use this command to add the latest version of capmonster_python to your project managed by poetry. ```bash poetry add capmonster_python ``` -------------------------------- ### Bypass Cloudflare Waiting Room (Async) Source: https://github.com/alperensert/capmonster_python/blob/master/docs/examples.md Use this asynchronous example to bypass Cloudflare Waiting Room challenges. A proxy is required for this task. Ensure you have the necessary website URL, website key, and base64-encoded page content. ```python import asyncio from capmonster_python import CapmonsterClient, TurnstileWaitingRoomTask, ProxyPayload async def main(): client = CapmonsterClient(api_key="") task = TurnstileWaitingRoomTask( websiteURL="https://example.com", websiteKey="", htmlPageBase64="", userAgent="Mozilla/5.0 (Windows NT 10.0; Win64; x64)...", proxy=ProxyPayload( proxyType="https", proxyAddress="192.168.1.1", proxyPort=8080) ) task_id = await client.create_task_async(task) result = await client.get_task_result_async(task_id) print(result) asyncio.run(main()) ``` -------------------------------- ### Bypass Cloudflare Waiting Room (Sync) Source: https://github.com/alperensert/capmonster_python/blob/master/docs/examples.md Use this synchronous example to bypass Cloudflare Waiting Room challenges. A proxy is required for this task. Ensure you have the necessary website URL, website key, and base64-encoded page content. ```python from capmonster_python import CapmonsterClient, TurnstileWaitingRoomTask, ProxyPayload client = CapmonsterClient(api_key="") task = TurnstileWaitingRoomTask( websiteURL="https://example.com", websiteKey="", htmlPageBase64="", userAgent="Mozilla/5.0 (Windows NT 10.0; Win64; x64)...", proxy=ProxyPayload( proxyType="https", proxyAddress="192.168.1.1", proxyPort=8080) ) task_id = client.create_task(task=task) result = client.get_task_result(task_id) print(result) ``` -------------------------------- ### reCAPTCHA v2 Solving (Sync) Source: https://github.com/alperensert/capmonster_python/blob/master/docs/examples.md Solve a reCAPTCHA v2 challenge synchronously. This example demonstrates creating a task and retrieving its result. ```python from capmonster_python import CapmonsterClient, RecaptchaV2Task client = CapmonsterClient(api_key="") task_id = client.create_task(task=RecaptchaV2Task( websiteURL="https://example.com", websiteKey="", isInvisible=False )) response = client.get_task_result(task_id=task_id) print(response.get("gRecaptchaResponse")) ``` -------------------------------- ### Get Account Balance (Async) Source: https://github.com/alperensert/capmonster_python/blob/master/docs/reference/client.md Asynchronously fetches the current account balance. Returns 0.0 if the balance cannot be determined. ```python async def get_balance_async(self) -> float ``` -------------------------------- ### reCAPTCHA v2 Solving (Async) Source: https://github.com/alperensert/capmonster_python/blob/master/docs/examples.md Solve a reCAPTCHA v2 challenge asynchronously. This example demonstrates creating a task and retrieving its result. ```python import asyncio from capmonster_python import CapmonsterClient, RecaptchaV2Task async def main(): client = CapmonsterClient(api_key="") task = RecaptchaV2Task( websiteURL="https://example.com", websiteKey="", isInvisible=False ) task_id = await client.create_task_async(task=task) result = await client.get_task_result_async(task_id=task_id) print(result.get("gRecaptchaResponse")) asyncio.run(main()) ``` -------------------------------- ### Get User Agent String (Sync) Source: https://github.com/alperensert/capmonster_python/blob/master/docs/reference/client.md Fetches a valid Windows User-Agent string from CapMonster Cloud for use in captcha tasks. ```python def get_user_agent(self) -> str ``` -------------------------------- ### Get User Agent String (Async) Source: https://github.com/alperensert/capmonster_python/blob/master/docs/reference/client.md Asynchronously fetches a valid Windows User-Agent string from CapMonster Cloud for use in captcha tasks. ```python async def get_user_agent_async(self) -> str ``` -------------------------------- ### Get Task Result (Sync) Source: https://github.com/alperensert/capmonster_python/blob/master/docs/reference/client.md Fetches the result of a specific task without waiting for completion. Returns an empty dictionary if the task is not yet ready. ```python def get_task_result(self, task_id: int) -> dict ``` -------------------------------- ### Clone Repository and Initialize Git Source: https://github.com/alperensert/capmonster_python/wiki/4.-Examples-and-Tests Steps to create a directory, initialize Git, and clone the CapMonster Python repository. ```bash mkdir capmonster-python cd capmonster-python git init git clone https://github.com/alperensert/capmonster_python.git ``` -------------------------------- ### Instantiate ProxyPayload Source: https://github.com/alperensert/capmonster_python/blob/master/docs/reference/abstract.md Use ProxyPayload to configure proxy settings for tasks that require them. You must provide the proxy type, address, and port. Authentication credentials can also be included. ```python from capmonster_python import ProxyPayload proxy = ProxyPayload( proxyType="https", proxyAddress="192.168.1.1", proxyPort=8080, proxyLogin="user", proxyPassword="pass" ) ``` -------------------------------- ### Initialize CapmonsterClient Source: https://github.com/alperensert/capmonster_python/blob/master/docs/reference/client.md Instantiate the client with your API key and optional parameters for timeout, retries, and retry delay. ```python CapmonsterClient(api_key: str, timeout: float = 30.0, max_retries: int = 120, retry_delay: float = 2.0) ``` -------------------------------- ### Initialize Capmonster Client Source: https://github.com/alperensert/capmonster_python/blob/master/README.md Instantiate the Capmonster client with your API key and optional parameters for timeout, retries, and delay. ```python CapmonsterClient(api_key, timeout=30.0, max_retries=120, retry_delay=2.0) ``` -------------------------------- ### Context Managers Source: https://github.com/alperensert/capmonster_python/blob/master/README.md Both synchronous and asynchronous context managers are supported for proper connection cleanup. ```APIDOC ### Context Managers Both sync and async context managers are supported for proper connection cleanup. ``` -------------------------------- ### FunCaptchaTask Source: https://github.com/alperensert/capmonster_python/blob/master/docs/reference/funcaptcha.md Initiates a FunCaptcha task to solve challenges on a given website. ```APIDOC ## FunCaptchaTask ### Description Solves FunCaptcha (Arkose Labs) challenges. ### Method POST ### Endpoint /funCaptcha ### Parameters #### Request Body - **websiteURL** (string) - Required - URL of the page where the captcha is located. - **websitePublicKey** (string) - Required - FunCaptcha public key (pk). - **funcaptchaApiJSSubdomain** (string | None) - Optional - Arkose Labs subdomain (surl). Only if it differs from `client-api.arkoselabs.com`. - **data** (string | None) - Optional - Additional data parameter, required if the site uses `data[blob]`. - **cookies** (string | None) - Optional - Additional cookies in `cookieName1=value1; cookieName2=value2` format. - **userAgent** (string | None) - Optional - Browser User-Agent string. - **proxy** (ProxyPayload | None) - Optional - Proxy settings. ### Request Example { "websiteURL": "https://example.com", "websitePublicKey": "YOUR_PUBLIC_KEY", "funcaptchaApiJSSubdomain": null, "data": null, "cookies": null, "userAgent": "Mozilla/5.0...", "proxy": { "type": "http", "uri": "http://user:password@host:port" } } ### Response #### Success Response (200) - **taskId** (string) - The ID of the created task. #### Response Example { "taskId": "1234567890" } ``` -------------------------------- ### Castle Solver Configuration Source: https://github.com/alperensert/capmonster_python/blob/master/docs/reference/castle.md Configuration options for the Castle solver task. ```APIDOC ## Castle Task **API type:** `CustomTask` (with `class: "Castle"`) ### Parameters #### Required Parameters - **websiteURL** (str) - URL of the page where Castle is located. - **websiteKey** (str) - Castle publishable key. - **metadata** (CastleMetadata) - Castle-specific metadata. #### Optional Parameters - **userAgent** (str | None) - Browser User-Agent string. Defaults to None. - **proxy** (ProxyPayload | None) - Proxy settings. Defaults to None. ## CastleMetadata ### Parameters #### Required Parameters - **wUrl** (str) - Link to `cw.js` file. - **swUrl** (str) - Link to `csw.js` file. #### Optional Parameters - **count** (int | None) - Number of tokens to generate (default 1, max 49). Defaults to None. ``` -------------------------------- ### Get Task Result (Async) Source: https://github.com/alperensert/capmonster_python/blob/master/docs/reference/client.md Asynchronously fetches the result of a specific task without waiting for completion. Returns an empty dictionary if the task is not yet ready. ```python async def get_task_result_async(self, task_id: int) -> dict ``` -------------------------------- ### Solve reCAPTCHA v3 Enterprise (Async) Source: https://github.com/alperensert/capmonster_python/blob/master/docs/examples.md Use this snippet for solving Google reCAPTCHA v3 Enterprise challenges asynchronously. Ensure you have the 'asyncio' library and 'capmonster_python' installed. ```python import asyncio from capmonster_python import CapmonsterClient, RecaptchaV3EnterpriseTask async def main(): client = CapmonsterClient(api_key="") task = RecaptchaV3EnterpriseTask( websiteURL="https://example.com", websiteKey="", minScore=0.7, pageAction="login" ) task_id = await client.create_task_async(task) result = await client.get_task_result_async(task_id) print(result.get("gRecaptchaResponse")) asyncio.run(main()) ``` -------------------------------- ### Configure Proxy and User Agent for FunCaptcha Source: https://github.com/alperensert/capmonster_python/wiki/1.-Usage Configure proxy and user agent settings for FuncaptchaTask. This allows for more specific task execution. ```python from capmonster import FuncaptchaTask capmonster = FuncaptchaTask("API_KEY") capmonster.set_proxy("http", "8.8.8.8", 8080) capmonster.set_user_agent("Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Firefox/91.0") task_id = capmonster.create_task("website_url", "website_public_key") result = capmonster.join_task_result(task_id) print(result.get("token")) ``` -------------------------------- ### Solve Binance CAPTCHA (Async) Source: https://github.com/alperensert/capmonster_python/blob/master/docs/examples.md Use this for solving Binance CAPTCHAs asynchronously, typically for login flows. Requires an API key, website details, and a `validateId`. ```python import asyncio from capmonster_python import CapmonsterClient, BinanceTask async def main(): client = CapmonsterClient(api_key="") task = BinanceTask( websiteURL="https://binance.com", websiteKey="binance-key", validateId="securityCheckResponseValidateId_value" ) task_id = await client.create_task_async(task) result = await client.get_task_result_async(task_id) print(result) asyncio.run(main()) ``` -------------------------------- ### Solve Binance CAPTCHA (Sync) Source: https://github.com/alperensert/capmonster_python/blob/master/docs/examples.md Use this for solving Binance CAPTCHAs synchronously, typically for login flows. Requires an API key, website details, and a `validateId`. ```python from capmonster_python import CapmonsterClient, BinanceTask client = CapmonsterClient(api_key="") task_id = client.create_task(BinanceTask( websiteURL="https://binance.com", websiteKey="binance-key", validateId="securityCheckResponseValidateId_value" )) result = client.get_task_result(task_id) print(result) ``` -------------------------------- ### Configure Proxy and User Agent for GeeTest Source: https://github.com/alperensert/capmonster_python/wiki/1.-Usage Configure proxy and user agent for GeeTestTask. This allows for custom network settings when solving GeeTest captchas. ```python from capmonster_python import GeeTestTask capmonster_python = GeeTestTask("API_KEY") capmonster.set_proxy("http", "8.8.8.8", 8080) capmonster.set_user_agent("Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Firefox/91.0") task_id = capmonster_python.create_task("website_url", "gt", "challenge") result= capmonster_python.join_task_result(task_id) print(result.get("challenge")) print(result.get("seccode")) print(result.get("validate")) ``` -------------------------------- ### CapmonsterClient Initialization Source: https://github.com/alperensert/capmonster_python/blob/master/README.md Initializes the Capmonster client with an API key and optional parameters for timeout, retries, and retry delay. ```APIDOC ## CapmonsterClient Constructor ### Description Initializes the Capmonster client. ### Parameters - **api_key** (string) - Required - Your Capmonster API key. - **timeout** (float) - Optional - The timeout in seconds for API requests. Defaults to 30.0. - **max_retries** (int) - Optional - The maximum number of retries for failed requests. Defaults to 120. - **retry_delay** (float) - Optional - The delay in seconds between retries. Defaults to 2.0. ``` -------------------------------- ### Solve Imperva Challenge (Sync) Source: https://github.com/alperensert/capmonster_python/blob/master/docs/examples.md Use this for solving Imperva challenges synchronously. Requires the website URL and metadata including the Incapsula script URL and cookie. ```python from capmonster_python import CapmonsterClient, ImpervaTask, ImpervaTaskMetadata client = CapmonsterClient(api_key="") task_id = client.create_task(ImpervaTask( websiteURL="https://example.com", metadata=ImpervaTaskMetadata( incapsulaScriptUrl="https://example.com/js.inc", incapsulaCookie="visid_incap_12345=...", ) )) result = client.get_task_result(task_id) print(result) ``` -------------------------------- ### CapmonsterClient Constructor Source: https://github.com/alperensert/capmonster_python/blob/master/docs/reference/client.md Initializes the CapmonsterClient with your API key and optional configuration for timeouts, retries, and retry delays. ```APIDOC ## CapmonsterClient Constructor Initializes the CapmonsterClient. ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters - **api_key** (str) - Required - Your Capmonster Cloud API key. - **timeout** (float) - Optional - HTTP request timeout in seconds. Defaults to `30.0`. - **max_retries** (int) - Optional - Maximum number of polling attempts in `join_task_result` / `solve`. Defaults to `120`. - **retry_delay** (float) - Optional - Delay in seconds between polling attempts. Defaults to `2.0`. ``` -------------------------------- ### CapmonsterAPIException Constructor Source: https://github.com/alperensert/capmonster_python/blob/master/docs/reference/exceptions.md Initializes a CapmonsterAPIException with error details from the API. ```python CapmonsterAPIException(error_id, error_code, error_description) ``` -------------------------------- ### Solve Amazon WAF Challenge (Sync) Source: https://github.com/alperensert/capmonster_python/blob/master/docs/examples.md Use this snippet for solving Amazon WAF challenges synchronously. Provide the required website URL, keys, and script paths. ```python from capmonster_python import CapmonsterClient, AmazonTask client = CapmonsterClient(api_key="") task_id = client.create_task(AmazonTask( websiteURL="https://example.com", websiteKey="", captchaScript="https://example.com/jsapi.js", challengeScript="https://example.com/challenge.js", context="", iv="" )) result = client.get_task_result(task_id) print(result) ``` -------------------------------- ### Solve Imperva Challenge (Async) Source: https://github.com/alperensert/capmonster_python/blob/master/docs/examples.md Use this for solving Imperva challenges asynchronously. Requires the website URL and metadata including the Incapsula script URL and cookie. ```python import asyncio from capmonster_python import CapmonsterClient, ImpervaTask, ImpervaTaskMetadata async def main(): client = CapmonsterClient(api_key="") task = ImpervaTask( websiteURL="https://example.com", metadata=ImpervaTaskMetadata( incapsulaScriptUrl="https://example.com/js.inc", incapsulaCookie="visid_incap_12345=...", ) ) task_id = await client.create_task_async(task) result = await client.get_task_result_async(task_id) print(result) asyncio.run(main()) ``` -------------------------------- ### Solve TenDI CAPTCHA (Sync) Source: https://github.com/alperensert/capmonster_python/blob/master/docs/examples.md Use this snippet to solve TenDI-based CAPTCHA challenges synchronously. A `websiteKey` and proxy configuration are required. ```python from capmonster_python import CapmonsterClient, TenDITask, ProxyPayload client = CapmonsterClient(api_key="") task = TenDITask( websiteURL="https://example.com", websiteKey="189123456", proxy=ProxyPayload( proxyType="https", proxyAddress="192.168.1.1", proxyPort=8080, proxyLogin="", proxyPassword="" ) ) task_id = client.create_task(task=task) result = client.get_task_result(task_id) print(result) ``` -------------------------------- ### Solve Altcha Challenge (Sync) Source: https://github.com/alperensert/capmonster_python/blob/master/docs/examples.md Use this synchronous method to solve Altcha challenges. Provide the website URL and required metadata for the challenge. ```python from capmonster_python import CapmonsterClient, AltchaTask, AltchaMetadata client = CapmonsterClient(api_key="") task_id = client.create_task(AltchaTask( websiteURL="https://example.com", metadata=AltchaMetadata( challenge="", iterations="", salt="", signature="" ) )) result = client.get_task_result(task_id) print(result) ``` -------------------------------- ### Solve Altcha Challenge (Async) Source: https://github.com/alperensert/capmonster_python/blob/master/docs/examples.md Use this asynchronous method to solve Altcha challenges. Ensure you have the necessary metadata like challenge, iterations, salt, and signature. ```python import asyncio from capmonster_python import CapmonsterClient, AltchaTask, AltchaMetadata async def main(): client = CapmonsterClient(api_key="") task = AltchaTask( websiteURL="https://example.com", metadata=AltchaMetadata( challenge="", iterations="", salt="", signature="" ) ) task_id = await client.create_task_async(task) result = await client.get_task_result_async(task_id) print(result) asyncio.run(main()) ``` -------------------------------- ### Solve Amazon WAF Challenge (Async) Source: https://github.com/alperensert/capmonster_python/blob/master/docs/examples.md Use this snippet for solving Amazon WAF challenges asynchronously. Ensure you have the necessary website URL, keys, and script paths. ```python import asyncio from capmonster_python import CapmonsterClient, AmazonTask async def main(): client = CapmonsterClient(api_key="") task = AmazonTask( websiteURL="https://example.com", websiteKey="", captchaScript="https://example.com/jsapi.js", challengeScript="https://example.com/challenge.js", context="", iv="" ) task_id = await client.create_task_async(task) result = await client.get_task_result_async(task_id) print(result) asyncio.run(main()) ``` -------------------------------- ### Solve GeeTest v4 Captcha (Sync) Source: https://github.com/alperensert/capmonster_python/blob/master/docs/examples.md Use this for solving advanced GeeTest v4 captchas synchronously. Requires gt and initParameters, and the challenge must be dynamically generated and fresh. ```python from capmonster_python import CapmonsterClient, GeeTestV4Task client = CapmonsterClient(api_key="") task_id = client.create_task(GeeTestV4Task( websiteURL="https://example.com", gt="", initParameters={"riskType": "slide"} )) result = client.get_task_result(task_id) print(result) ``` -------------------------------- ### GeeTestTask create_task Source: https://github.com/alperensert/capmonster_python/wiki/2.-API Creates a task to solve a GeeTest captcha. Requires the website URL, gt key, and challenge key. Optional parameters include API server subdomain and get_lib. ```APIDOC ## GeeTestTask create_task ### Description Creates a task to solve a GeeTest captcha. ### Method create_task ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **client_key** (String) - Required - Your unique key to solve captchas - **website_url** (String) - Required - Address of the page on which the captcha is ricognized - **gt** (String) - Required - The GeeTest identifier key for the domain. - **challenge** (String) - Required - A dynamic key. Each time our API is called, we need to get a new key value. - **api_server_subdomain** (String) - Optional - Optional parameter. May be required for some sites. - **get_lib** (String) - Optional - Optional parameter. May be required for some sites. ``` -------------------------------- ### FuncaptchaTask create_task Source: https://github.com/alperensert/capmonster_python/wiki/2.-API Creates a task to solve a FunCaptcha. Requires the website URL and public key. Optional parameters include API JS subdomain, data blob, cookies, and a no_cache flag. ```APIDOC ## FuncaptchaTask create_task ### Description Creates a task to solve a FunCaptcha. ### Method create_task ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **client_key** (String) - Required - Your unique key to solve captchas - **website_url** (String) - Required - Address of a webpage with FunCaptcha - **website_public_key** (String) - Required - FunCaptcha website key - **api_js_subdomain** (String) - Optional - A special subdomain of funcaptcha.com, from which the JS captcha widget should be loaded. - **data_blob** (String) - Optional - Additional parameter that may be required by Funcaptcha implementation. - **cookies** (Dict, List, String) - Optional - Additional cookies which we must use during interaction with target page or Google. - **no_cache** (Boolean) - Optional - If true, attempts to bypass cache for token verification. ``` -------------------------------- ### Use CapmonsterClient as a Context Manager (Sync) Source: https://github.com/alperensert/capmonster_python/blob/master/docs/reference/client.md Utilize the synchronous context manager to ensure HTTP connections are properly closed after use. Replace 'YOUR_KEY' with your actual API key. ```python with CapmonsterClient(api_key="YOUR_KEY") as client: result = client.solve(task) ``` -------------------------------- ### Solve TenDI CAPTCHA (Async) Source: https://github.com/alperensert/capmonster_python/blob/master/docs/examples.md Use this snippet to solve TenDI-based CAPTCHA challenges asynchronously. A `websiteKey` and proxy configuration are required. ```python import asyncio from capmonster_python import CapmonsterClient, TenDITask, ProxyPayload async def main(): client = CapmonsterClient(api_key="") task = TenDITask( websiteURL="https://example.com", websiteKey="189123456", proxy=ProxyPayload( proxyType="https", proxyAddress="192.168.1.1", proxyPort=8080, proxyLogin="", proxyPassword="" ) ) task_id = await client.create_task_async(task) result = await client.get_task_result_async(task_id) print(result) asyncio.run(main()) ``` -------------------------------- ### Solve Castle Challenge (Sync) Source: https://github.com/alperensert/capmonster_python/blob/master/docs/examples.md This synchronous method solves Castle challenges. Ensure you provide the website URL, website key, and the relevant metadata for the challenge. ```python from capmonster_python import CapmonsterClient, CastleTask, CastleMetadata client = CapmonsterClient(api_key="") task_id = client.create_task(CastleTask( websiteURL="https://example.com", websiteKey="", metadata=CastleMetadata( wUrl="https://example.com/cw.js", swUrl="https://example.com/csw.js" ) )) result = client.get_task_result(task_id) print(result) ``` -------------------------------- ### Custom Task Payloads Source: https://github.com/alperensert/capmonster_python/blob/master/README.md Information on using `VanillaTaskPayload` for custom task payloads. ```APIDOC ### Custom Task Payloads Don't see your captcha type? Use `VanillaTaskPayload` to build custom task payloads without waiting for an SDK update. ``` -------------------------------- ### solve Source: https://github.com/alperensert/capmonster_python/blob/master/README.md Creates a CAPTCHA solving task and polls until the solution is ready. ```APIDOC ## solve ### Description Creates a task and polls until solved. ### Method `solve(task)` ### Parameters - **task** (object) - Required - The task payload defining the CAPTCHA to solve. ``` -------------------------------- ### Solve ImageToText (Async) Source: https://github.com/alperensert/capmonster_python/blob/master/docs/examples.md This snippet demonstrates how to solve ImageToText challenges asynchronously. It requires a base64 encoded image string and the 'asyncio' library. ```python import asyncio from capmonster_python import CapmonsterClient, ImageToTextTask async def main(): client = CapmonsterClient(api_key="") task = ImageToTextTask( body="", recognizingThreshold=95 ) task_id = await client.create_task_async(task=task) result = await client.get_task_result_async(task_id=task_id) print(result.get("text")) asyncio.run(main()) ``` -------------------------------- ### Define Custom Task with VanillaTaskPayload Source: https://github.com/alperensert/capmonster_python/blob/master/docs/reference/abstract.md Extend VanillaTaskPayload to create custom task types not yet supported by the SDK. This allows for custom fields and integrates with existing proxy and user-agent configurations. ```python from capmonster_python import VanillaTaskPayload class CustomCaptchaTask(VanillaTaskPayload): type: str = "NewCustomTask" custom_field: str ``` -------------------------------- ### Solve GeeTest v4 Captcha (Async) Source: https://github.com/alperensert/capmonster_python/blob/master/docs/examples.md Use this for solving advanced GeeTest v4 captchas asynchronously. Requires gt and initParameters, and the challenge must be dynamically generated and fresh. ```python import asyncio from capmonster_python import CapmonsterClient, GeeTestV4Task async def main(): client = CapmonsterClient(api_key="") task = GeeTestV4Task( websiteURL="https://example.com", gt="", initParameters={"riskType": "slide"} ) task_id = await client.create_task_async(task) result = await client.get_task_result_async(task_id) print(result) asyncio.run(main()) ``` -------------------------------- ### TenDI Solver Source: https://github.com/alperensert/capmonster_python/blob/master/docs/reference/tendi.md Use this task to solve TenDI-based captcha challenges. It requires the website URL, website key, and proxy information. ```APIDOC ## TenDI Solver ### Description Solves TenDI-based captcha challenges. ### API Type `CustomTask` (with `class: "TenDI"`) ### Parameters #### Required Parameters - **websiteURL** (str) - Address of the page with the captcha. - **websiteKey** (str) - captchaAppId — unique parameter for your site. - **proxy** (ProxyPayload) - Proxy settings. #### Optional Parameters - **userAgent** (str | None) - Browser User-Agent string. Defaults to None. ``` -------------------------------- ### Use CapmonsterClient as a Context Manager (Async) Source: https://github.com/alperensert/capmonster_python/blob/master/docs/reference/client.md Utilize the asynchronous context manager to ensure HTTP connections are properly closed after use. Replace 'YOUR_KEY' with your actual API key. ```python async with CapmonsterClient(api_key="YOUR_KEY") as client: result = await client.solve_async(task) ``` -------------------------------- ### create_task Source: https://github.com/alperensert/capmonster_python/blob/master/README.md Creates a CAPTCHA solving task and returns its ID. ```APIDOC ## create_task ### Description Creates a task, returns `task_id`. ### Method `create_task(task)` ### Parameters - **task** (object) - Required - The task payload defining the CAPTCHA to create. ``` -------------------------------- ### Solve Basilisk CAPTCHA (Async) Source: https://github.com/alperensert/capmonster_python/blob/master/docs/examples.md Use this for solving Basilisk CAPTCHAs asynchronously. Requires an API key and website details. ```python import asyncio from capmonster_python import CapmonsterClient, BasiliskTask async def main(): client = CapmonsterClient(api_key="") task = BasiliskTask( websiteURL="https://example.com", websiteKey="site_key_value" ) task_id = await client.create_task_async(task=task) result = await client.get_task_result_async(task_id=task_id) print(result) asyncio.run(main()) ``` -------------------------------- ### Solve Castle Challenge (Async) Source: https://github.com/alperensert/capmonster_python/blob/master/docs/examples.md This asynchronous function solves Castle challenges. It requires the website URL, publishable key, and specific metadata for the challenge URLs. ```python import asyncio from capmonster_python import CapmonsterClient, CastleTask, CastleMetadata async def main(): client = CapmonsterClient(api_key="") task = CastleTask( websiteURL="https://example.com", websiteKey="", metadata=CastleMetadata( wUrl="https://example.com/cw.js", swUrl="https://example.com/csw.js" ) ) task_id = await client.create_task_async(task) result = await client.get_task_result_async(task_id) print(result) asyncio.run(main()) ``` -------------------------------- ### Configurable Polling (Sync) Source: https://github.com/alperensert/capmonster_python/blob/master/docs/examples.md Customize polling behavior with max_retries and retry_delay when waiting for task results in synchronous mode. ```python from capmonster_python import CapmonsterClient, RecaptchaV2Task client = CapmonsterClient( api_key="", max_retries=60, retry_delay=2.0 ) result = client.solve(RecaptchaV2Task( websiteURL="https://example.com", websiteKey="" )) print(result) ``` -------------------------------- ### RecaptchaV2Task.create_task Source: https://github.com/alperensert/capmonster_python/wiki/2.-API Creates a task to solve reCAPTCHA v2 challenges. Requires the website URL and the website key. ```APIDOC ## RecaptchaV2Task.create_task ### Description Creates a task to solve reCAPTCHA v2 challenges. Requires the website URL and the website key. ### Method create_task ### Parameters #### Path Parameters - None #### Query Parameters - None #### Request Body - **client_key** (String) - Required - Your unique key to solve captchas - **website_url** (String) - Required - Address of a webpage with Google ReCaptcha - **website_key** (String) - Required - Recaptcha website key - **cookies** (Dict, List, String) - Optional - Additional cookies which we must use during interaction with target page or Google. If passed as string, format: cookiename1=cookievalue1; cookiename2=cookievalue2 - **recaptcha_s_value** (String) - Optional - Some custom implementations may contain additional "data-s" parameter in ReCaptcha2 div, which is in fact a one-time token and must be grabbed every time you want to solve a ReCaptcha2. - **no_cache** (Boolean) - Optional - Use to bypass cache if the token is rejected by the site. ### Request Example ```json { "client_key": "YOUR_CLIENT_KEY", "website_url": "https://www.google.com/recaptcha/api2/demo", "website_key": "6Le-wvkSAAAAAPBMRTvw0Q4Muexq9bi0DJwx_mJ-" } ``` ### Response #### Success Response (200) - **captcha_id** (String) - The ID of the created captcha task #### Response Example ```json { "captcha_id": "12345-67890" } ``` ``` -------------------------------- ### Create Captcha Task (Async) Source: https://github.com/alperensert/capmonster_python/blob/master/docs/reference/client.md Asynchronously creates a captcha-solving task and returns its unique identifier. An optional callback URL can be provided for completion notifications. ```python async def create_task_async(self, task: TaskPayload, callback_url: str | None = None) -> int ``` -------------------------------- ### Solve GeeTest v3 Captcha (Sync) Source: https://github.com/alperensert/capmonster_python/blob/master/docs/examples.md Use this for solving GeeTest v3 captchas synchronously. Ensure you have the correct website URL, gt, and challenge values. ```python from capmonster_python import CapmonsterClient, GeeTestV3Task client = CapmonsterClient(api_key="") task_id = client.create_task(GeeTestV3Task( websiteURL="https://example.com", gt="", challenge="" )) result = client.get_task_result(task_id) print(result) ``` -------------------------------- ### HCaptchaTask.create_task Source: https://github.com/alperensert/capmonster_python/wiki/2.-API Creates a task to solve hCaptcha challenges. Requires the website URL and the website key. ```APIDOC ## HCaptchaTask.create_task ### Description Creates a task to solve hCaptcha challenges. Requires the website URL and the website key. ### Method create_task ### Parameters #### Path Parameters - None #### Query Parameters - None #### Request Body - **client_key** (String) - Required - Your unique key to solve captchas - **website_url** (String) - Required - Address of a webpage with hCaptcha - **website_key** (String) - Required - hCaptcha website key - **is_invisible** (Boolean) - Optional - Use `True` for invisible version of hcaptcha - **custom_data** (String) - Optional - Custom data that is used in some implementations of hCaptcha, mostly with isInvisible=true. IMPORTANT: You MUST provide an user agent if you submit captcha with data parameter. - **cookies** (Dict, List, String) - Optional - Additional cookies which we must use during interaction with target page or Google. If passed as string, format: cookiename1=cookievalue1; cookiename2=cookievalue2 - **no_cache** (Boolean) - Optional - Use to bypass cache if the token is rejected by the site. ### Request Example ```json { "client_key": "YOUR_CLIENT_KEY", "website_url": "https://www.example.com", "website_key": "SOME_WEBSITE_KEY" } ``` ### Response #### Success Response (200) - **captcha_id** (String) - The ID of the created captcha task #### Response Example ```json { "captcha_id": "12345-67890" } ``` ``` -------------------------------- ### Solve Basilisk CAPTCHA (Sync) Source: https://github.com/alperensert/capmonster_python/blob/master/docs/examples.md Use this for solving Basilisk CAPTCHAs synchronously. Requires an API key and website details. ```python from capmonster_python import CapmonsterClient, BasiliskTask client = CapmonsterClient(api_key="") task_id = client.create_task(BasiliskTask( websiteURL="https://example.com", websiteKey="site_key_value" )) result = client.get_task_result(task_id=task_id) print(result) ``` -------------------------------- ### Solve Altcha Challenge Source: https://github.com/alperensert/capmonster_python/blob/master/docs/reference/altcha.md Initiates a task to solve an Altcha proof-of-work challenge. This requires providing the website URL, a unique challenge identifier, and other relevant metadata. ```APIDOC ## POST /createTask ### Description Submits a request to the CapMonster Cloud API to solve an Altcha proof-of-work challenge. ### Method POST ### Endpoint /createTask ### Parameters #### Request Body - **clientKey** (string) - Required - Your CapMonster API key. - **task** (object) - Required - The task details. - **type** (string) - Required - Must be set to "altcha". - **websiteURL** (string) - Required - Main page URL where Altcha is located. - **websiteKey** (string) - Optional - Defaults to "". - **metadata** (object) - Required - Altcha-specific metadata. - **challenge** (string) - Required - Unique task identifier obtained from the website. - **iterations** (string) - Required - Number of iterations (corresponds to `maxnumber` value). - **salt** (string) - Required - Salt obtained from the site, used for hash generation. - **signature** (string) - Required - Digital signature of the request. - **userAgent** (string | null) - Optional - Browser User-Agent string. - **proxy** (object | null) - Optional - Proxy settings. ### Request Example ```json { "clientKey": "YOUR_API_KEY", "task": { "type": "altcha", "websiteURL": "https://example.com", "websiteKey": "", "metadata": { "challenge": "some_challenge_string", "iterations": "100000", "salt": "some_salt_string", "signature": "some_signature_string" }, "userAgent": "Mozilla/5.0 ...", "proxy": { "type": "http", "uri": "http://user:password@host:port" } } } ``` ### Response #### Success Response (200) - **errorId** (integer) - Error code. 0 if no error. - **taskId** (integer) - ID of the task to be solved. - **solution** (object) - Solution to the task (if available immediately). - **captchaSolution** (string) - The solution to the Altcha challenge. #### Response Example ```json { "errorId": 0, "taskId": 123456789 } ``` ``` -------------------------------- ### Solve TSPD Challenge (Async) Source: https://github.com/alperensert/capmonster_python/blob/master/docs/examples.md Use this asynchronous method to solve TSPD challenges. Ensure you provide a valid API key, website URL, user agent, TSPD metadata (cookies and base64 encoded HTML), and proxy details. ```python import asyncio from capmonster_python import CapmonsterClient, TSPDTask, TSPDMetadata, ProxyPayload async def main(): client = CapmonsterClient(api_key="") task = TSPDTask( websiteURL="https://example.com", userAgent="Mozilla/5.0 (Windows NT 10.0; Win64; x64)வுகளை", metadata=TSPDMetadata( tspdCookie="", htmlPageBase64="" ), proxy=ProxyPayload( proxyType="https", proxyAddress="192.168.1.1", proxyPort=8080) ) task_id = await client.create_task_async(task) result = await client.get_task_result_async(task_id) print(result) asyncio.run(main()) ``` -------------------------------- ### Bypass Cloudflare Protection (cf_clearance) - Async Source: https://github.com/alperensert/capmonster_python/blob/master/docs/examples.md Use this for bypassing complex Cloudflare protection that requires a `cf_clearance` cookie and HTML snapshot, using an asynchronous approach. A proxy is required. ```python import asyncio from capmonster_python import CapmonsterClient, TurnstileCloudFlareTask, ProxyPayload async def main(): client = CapmonsterClient(api_key="") task = TurnstileCloudFlareTask( cloudflareTaskType="cf_clearance", websiteURL="https://example.com", websiteKey="", userAgent="Mozilla/5.0 (Windows NT 10.0; Win64; x64)...", htmlPageBase64="", proxy=ProxyPayload( proxyType="https", proxyAddress="192.168.1.1", proxyPort=8000) ) task_id = await client.create_task_async(task) result = await client.get_task_result_async(task_id) print(result) asyncio.run(main()) ``` -------------------------------- ### Solve ImageToText (Sync) Source: https://github.com/alperensert/capmonster_python/blob/master/docs/examples.md This snippet shows how to solve ImageToText challenges synchronously. Provide the base64 encoded image string to the ImageToTextTask. ```python from capmonster_python import CapmonsterClient, ImageToTextTask client = CapmonsterClient(api_key="") task = ImageToTextTask( body="", recognizingThreshold=95 ) task_id = client.create_task(task=task) response = client.get_task_result(task_id=task_id) print(response.get("text")) ``` -------------------------------- ### BinanceTask API Source: https://github.com/alperensert/capmonster_python/blob/master/docs/reference/binance.md Use this task to solve Binance CAPTCHA challenges. It's recommended for login flows only. ```APIDOC ## BinanceTask ### Description Solves Binance CAPTCHA challenges. Use only for login flows. ### Parameters #### Required Parameters - **websiteURL** (string) - Address of the main page where the captcha is solved. - **websiteKey** (string) - A unique parameter for your website's section. - **validateId** (string) - Dynamic key — the value of `validateId`, `securityId`, or `securityCheckResponseValidateId`. #### Optional Parameters - **userAgent** (string | None) - Browser User-Agent string. Defaults to None. - **proxy** (ProxyPayload | None) - Proxy settings. Defaults to None. ``` -------------------------------- ### Solve FunCaptcha Challenge (Sync) Source: https://github.com/alperensert/capmonster_python/blob/master/docs/examples.md This synchronous snippet solves FunCaptcha (Arkose Labs) challenges. Provide the correct website URL and public key. ```python from capmonster_python import CapmonsterClient, FunCaptchaTask client = CapmonsterClient(api_key="") task_id = client.create_task(FunCaptchaTask( websiteURL="https://example.com", websitePublicKey="" )) result = client.get_task_result(task_id) print(result) ``` -------------------------------- ### Create Captcha Task (Sync) Source: https://github.com/alperensert/capmonster_python/blob/master/docs/reference/client.md Creates a captcha-solving task and returns its unique identifier. An optional callback URL can be provided for completion notifications. ```python def create_task(self, task: TaskPayload, callback_url: str | None = None) -> int ``` -------------------------------- ### solve Source: https://github.com/alperensert/capmonster_python/blob/master/docs/reference/client.md A convenience method that combines creating a task and polling for its result into a single operation. ```APIDOC ## solve Convenience method that creates a task and polls for its result in one call. ### Description Convenience method that creates a task and polls for its result in one call. Equivalent to `create_task()` followed by `join_task_result()`. ### Method POST (implied) ### Endpoint (Not explicitly defined, assumed to be part of the client's API) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **task** (TaskPayload) - Required - The task configuration payload. - **callback_url** (str | None) - Optional - Optional callback URL for task completion. Defaults to `None`. ``` -------------------------------- ### Async solve() Method for CapmonsterClient Source: https://github.com/alperensert/capmonster_python/blob/master/docs/examples.md The async solve() method simplifies CAPTCHA solving by combining task creation and result retrieval into a single asynchronous call. It's useful for quick, straightforward CAPTCHA resolutions. ```python import asyncio from capmonster_python import CapmonsterClient, RecaptchaV2Task async def main(): client = CapmonsterClient(api_key="") result = await client.solve_async(RecaptchaV2Task( websiteURL="https://example.com", websiteKey="" )) print(result.get("gRecaptchaResponse")) asyncio.run(main()) ``` -------------------------------- ### Solve GeeTest v3 Captcha (Async) Source: https://github.com/alperensert/capmonster_python/blob/master/docs/examples.md Use this for solving GeeTest v3 captchas asynchronously. Ensure you have the correct website URL, gt, and challenge values. ```python import asyncio from capmonster_python import CapmonsterClient, GeeTestV3Task async def main(): client = CapmonsterClient(api_key="") task = GeeTestV3Task( websiteURL="https://example.com", gt="", challenge="" ) task_id = await client.create_task_async(task) result = await client.get_task_result_async(task_id) print(result) asyncio.run(main()) ``` -------------------------------- ### get_user_agent Source: https://github.com/alperensert/capmonster_python/blob/master/docs/reference/client.md Fetches a currently valid User-Agent string for Windows from CapMonster Cloud. ```APIDOC ## get_user_agent Fetches the current valid Windows User-Agent string from CapMonster Cloud. ### Description Fetches the current valid Windows User-Agent string from CapMonster Cloud. ### Method GET (implied) ### Endpoint (Not explicitly defined, assumed to be part of the client's API) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Response #### Success Response - **user_agent** (str) - The current User-Agent string to use with captcha tasks. ``` -------------------------------- ### Sync solve() Method for CapmonsterClient Source: https://github.com/alperensert/capmonster_python/blob/master/docs/examples.md The sync solve() method simplifies CAPTCHA solving by combining task creation and result retrieval into a single synchronous call. It's useful for quick, straightforward CAPTCHA resolutions. ```python from capmonster_python import CapmonsterClient, RecaptchaV2Task client = CapmonsterClient(api_key="") result = client.solve(RecaptchaV2Task( websiteURL="https://example.com", websiteKey="" )) print(result.get("gRecaptchaResponse")) ```