Alibaba captcha¶
To import this module:
from python_rucaptcha.alibaba_captcha import AlibabaCaptcha
from python_rucaptcha.core.enums import AlibabaEnm
- class python_rucaptcha.alibaba_captcha.AlibabaCaptcha(websiteURL: str, sceneId: str, prefix: str, method: str | AlibabaEnm = AlibabaEnm.AlibabaTaskProxyless, userId: str | None = None, userUserId: str | None = None, verifyType: str | None = None, region: str | None = None, userCertifyId: str | None = None, apiGetLib: str | None = None, userAgent: str | None = None, proxyType: str | None = None, proxyAddress: str | None = None, proxyPort: int | None = None, proxyLogin: str | None = None, proxyPassword: str | None = None, *args, **kwargs)¶
Solve Alibaba captcha with a proxyless or customer-provided proxy task.
- __init__(websiteURL: str, sceneId: str, prefix: str, method: str | AlibabaEnm = AlibabaEnm.AlibabaTaskProxyless, userId: str | None = None, userUserId: str | None = None, verifyType: str | None = None, region: str | None = None, userCertifyId: str | None = None, apiGetLib: str | None = None, userAgent: str | None = None, proxyType: str | None = None, proxyAddress: str | None = None, proxyPort: int | None = None, proxyLogin: str | None = None, proxyPassword: str | None = None, *args, **kwargs)¶
- Parameters:
rucaptcha_key – User API key.
websiteURL (str) – Full URL of the page where Alibaba captcha is loaded.
sceneId (str) – Captcha scenario identifier.
prefix (str) – Captcha initialization prefix from the loading request.
method (str | AlibabaEnm) –
AlibabaTaskProxylessorAlibabaTask.userId (str | None) – Optional website-side user or session identifier.
userUserId (str | None) – Optional secondary user identifier.
verifyType (str | None) – Optional verification mechanism type.
region (str | None) – Optional Alibaba processing region.
userCertifyId (str | None) – Optional verification identifier.
apiGetLib (str | None) – Optional URL of the captcha JavaScript library.
userAgent (str | None) – Optional browser User-Agent.
proxyType (str | None) – Proxy type for
AlibabaTask.proxyAddress (str | None) – Proxy IP address or hostname.
proxyPort (int | None) – Proxy port.
proxyLogin (str | None) – Optional proxy login.
proxyPassword (str | None) – Optional proxy password.
kwargs – Additional task parameters.
- captcha_handler(**kwargs) dict¶
Synchronously submit and poll the Alibaba task.
- async aio_captcha_handler() dict¶
Asynchronously submit and poll the Alibaba task.
The required sceneId and prefix values, together with optional values
such as userId, verifyType, region, and userCertifyId, are
page-specific and should be extracted from the captcha initialization
requests. apiGetLib may also be generated dynamically.
The result is a JSON string in solution.data.tokens. Parse it with
json.loads before resending the Alibaba verification request.