ReCaptchaV2¶
To import this module:
from python3_anticaptcha.recaptcha_v2 import ReCaptchaV2
- class python3_anticaptcha.recaptcha_v2.ReCaptchaV2(api_key: str, captcha_type: CaptchaTypeEnm | str, websiteURL: str, websiteKey: str, recaptchaDataSValue: str | None = None, isInvisible: bool = False, enterprisePayload: dict | None = None, apiDomain: str | None = None, proxyType: ProxyTypeEnm | str | None = None, proxyAddress: str | None = None, proxyPort: int | None = None, proxyLogin: str | None = None, proxyPassword: str | None = None, userAgent: str | None = None, cookies: str | None = None, sleep_time: int = 10)¶
- __init__(api_key: str, captcha_type: CaptchaTypeEnm | str, websiteURL: str, websiteKey: str, recaptchaDataSValue: str | None = None, isInvisible: bool = False, enterprisePayload: dict | None = None, apiDomain: str | None = None, proxyType: ProxyTypeEnm | str | None = None, proxyAddress: str | None = None, proxyPort: int | None = None, proxyLogin: str | None = None, proxyPassword: str | None = None, userAgent: str | None = None, cookies: str | None = None, sleep_time: int = 10)¶
The class is used to work with ReCaptchaV2 and RecaptchaV2Enterprise.
- Parameters:
api_key (str) – Capsolver API key
captcha_type (CaptchaTypeEnm | str) – Captcha type
websiteURL (str) – Address of the webpage
websiteKey (str) – Recaptcha website key.
recaptchaDataSValue (str | None) – Value of ‘data-s’ parameter. Applies only to reCaptchas on Google web sites.
isInvisible (bool) – Specify whether or not reCaptcha is invisible. This will render an appropriate widget for our workers.
enterprisePayload (dict | None) – Additional parameters which should be passed to “grecaptcha.enterprise.render” method along with sitekey.
apiDomain (str | None) – Use this parameter to send the domain name from which the reCaptcha script should be served. Can have only one of two values: “www.google.com” or “www.recaptcha.net”. Do not use this parameter unless you understand what you are doing.
proxyType (ProxyTypeEnm | str | None) – Type of the proxy
proxyAddress (str | None) – Proxy IP address IPv4/IPv6. Not allowed to use: host names instead of IPs, transparent proxies (where client IP is visible), proxies from local networks (192.., 10.., 127…)
proxyPort (int | None) – Proxy port.
proxyLogin (str | None) – Proxy login.
proxyPassword (str | None) – Proxy password.
userAgent (str | None) – Browser UserAgent.
cookies (str | None) – Additional cookies that we should use in Google domains.
sleep_time (int) – The waiting time between requests to get the result of the Captcha
Examples
>>> ReCaptchaV2(api_key="99d7d111a0111dc11184111c8bb111da", ... captcha_type=CaptchaTypeEnm.RecaptchaV2TaskProxyless, ... websiteURL="https://www.recaptcha.com/en/adaptive-captcha-demo", ... websiteKey="6Lc_aCMTAAAAABx7u2N0D1XnVbI_v6ZdbM6rYf16", ... recaptchaDataSValue="12345678abc90123d45678ef90123a456b", ... isInvisible=False, ... ).captcha_handler() { "errorId": 0, "errorCode": None, "errorDescription": None, "status":"ready", "solution":{ "gRecaptchaResponse":"3AHJ_VuvYIB.......6a3" }, "cost": 0.002, "ip": "46.53.249.230", "createTime": 1679004358, "endTime": 1679004368, "solveCount": 0, "taskId": 396687629 }
>>> await ReCaptchaV2(api_key="99d7d111a0111dc11184111c8bb111da", ... captcha_type=CaptchaTypeEnm.RecaptchaV2Task, ... websiteURL="https://www.recaptcha.com/en/adaptive-captcha-demo", ... websiteKey="6Lc_aCMTAAAAABx7u2N0D1XnVbI_v6ZdbM6rYf16", ... recaptchaDataSValue="12345678abc90123d45678ef90123a456b", ... isInvisible=False, ... proxyType="http", ... proxyAddress="0.0.0.0", ... proxyPort=9988, ... proxyLogin="proxy_login", ... proxyPassword="proxy_password", ... userAgent="some_real_user_agent", ... cookies="some-cookies-data", ... ).aio_captcha_handler() { "errorId": 0, "errorCode": None, "errorDescription": None, "status":"ready", "solution":{ "gRecaptchaResponse":"3AHJ_VuvYIB.......6a3" }, "cost": 0.002, "ip": "46.53.249.230", "createTime": 1679004358, "endTime": 1679004368, "solveCount": 0, "taskId": 396687629 }
>>> ReCaptchaV2(api_key="99d7d111a0111dc11184111c8bb111da", ... captcha_type=CaptchaTypeEnm.RecaptchaV2EnterpriseTaskProxyless, ... websiteURL="https://www.recaptcha.com/en/adaptive-captcha-demo", ... websiteKey="6Lc_aCMTAAAAABx7u2N0D1XnVbI_v6ZdbM6rYf16", ... enterprisePayload={ ... "s": "SOME_ADDITIONAL_TOKEN" ... }, ... apiDomain="www.google.com", ... ).captcha_handler() { "errorId": 0, "errorCode": None, "errorDescription": None, "status":"ready", "solution":{ "gRecaptchaResponse":"3AHJ_VuvYIB.......6a3" }, "cost": 0.002, "ip": "46.53.249.230", "createTime": 1679004358, "endTime": 1679004368, "solveCount": 0, "taskId": 396687629 }
- async aio_captcha_handler(**additional_params) dict ¶
Asynchronous method for captcha solving
- Parameters:
additional_params – Some additional parameters that will be used in creating the task and will be passed to the payload under
task
key. LikeproxyLogin
,proxyPassword
and etc. - more info in service docs- Returns:
Dict with full server response
- Return type:
dict
Notes
Check class docstirng for more info
- captcha_handler(**additional_params) dict ¶
Synchronous method for captcha solving
- Parameters:
additional_params – Some additional parameters that will be used in creating the task and will be passed to the payload under
task
key. LikeproxyLogin
,proxyPassword
and etc. - more info in service docs- Returns:
Dict with full server response
- Return type:
dict
Notes
Check class docstirng for more info
- set_callback_url(callbackUrl: str) None ¶
Method for callbackUrl param set.
- Parameters:
callbackUrl (str) –
Optional web address where we can send the results of captcha task processing. Contents are sent by AJAX POST request and are identical
to the contents of getTaskResult method.