Skip to content

Commit

Permalink
Update hcaptcha.py
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreiDrang committed Dec 7, 2023
1 parent e8015d5 commit dcea062
Showing 1 changed file with 38 additions and 46 deletions.
84 changes: 38 additions & 46 deletions src/python_rucaptcha/hcaptcha.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
class HCaptcha(BaseCaptcha):
def __init__(
self,
sitekey: str,
pageurl: str,
websiteURL: str,
websiteKey: str,
method: str = HCaptchaEnm.HCaptchaTaskProxyless.value,
*args,
**kwargs,
Expand All @@ -16,73 +16,65 @@ def __init__(
Args:
rucaptcha_key: User API key
sitekey: The value of the `data-sitekey` parameter found on the site
pageurl: Full URL of the captcha page
websiteURL: Full URL of the captcha page
websiteKey: The value of the `data-sitekey` parameter found on the site
method: Captcha type
kwargs: Not required params for task creation request
Examples:
>>> HCaptcha(rucaptcha_key="aa9011f31111181111168611f1151122",
... sitekey="3ceb8624-1970-4e6b-91d5-70317b70b651",
... pageurl="https://rucaptcha.com/demo/hcaptcha",
... websiteKey="3ceb8624-1970-4e6b-91d5-70317b70b651",
... websiteURL="https://rucaptcha.com/demo/hcaptcha",
... method=HCaptchaEnm.HCaptchaTaskProxyless.value
... ).captcha_handler()
{
"captchaSolve": "P1_eyJ.....cp_J",
"taskId": 73052314114,
"error": False,
"errorBody": None
"errorId":0,
"status":"ready",
"solution":{
"token":"P1_eyJ0eXAiOiJKV...1LDq89KyJ5A",
"respKey":"E0_eyJ0eXAiOiJK...y2w5_YbP8PGuJBBo",
"userAgent":"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.5614.0 Safari/537.36",
"gRecaptchaResponse":"P1_eyJ0eXAiOiJKV...1LDq89KyJ5A"
},
"cost":"0.00299",
"ip":"1.2.3.4",
"createTime":1692863536,
"endTime":1692863556,
"solveCount":1,
"taskId": 73243152973,
}
>>> await HCaptcha(rucaptcha_key="aa9011f31111181111168611f1151122",
... sitekey="3ceb8624-1970-4e6b-91d5-70317b70b651",
... pageurl="https://rucaptcha.com/demo/hcaptcha",
... websiteKey="3ceb8624-1970-4e6b-91d5-70317b70b651",
... websiteURL="https://rucaptcha.com/demo/hcaptcha",
... method=HCaptchaEnm.HCaptchaTaskProxyless.value
... ).aio_captcha_handler()
{
"captchaSolve": "P1_eyJ.....cp_J",
"taskId": 73052314114,
"error": False,
"errorBody": None
}
DeathByCaptcha:
>>> HCaptcha(rucaptcha_key="some_username:some_password",
... service_type="deathbycaptcha",
... sitekey="3ceb8624-1970-4e6b-91d5-70317b70b651",
... pageurl="https://rucaptcha.com/demo/hcaptcha",
... method=HCaptchaEnm.HCaptchaTaskProxyless.value
... ).captcha_handler()
{
'captchaSolve': '03A....8h',
'taskId': '73043008354',
'error': False,
'errorBody': None
}
>>> await HCaptcha(rucaptcha_key="some_username:some_password",
... service_type="deathbycaptcha",
... sitekey="3ceb8624-1970-4e6b-91d5-70317b70b651",
... pageurl="https://rucaptcha.com/demo/hcaptcha",
... method=HCaptchaEnm.HCaptchaTaskProxyless.value
... ).aio_captcha_handler()
{
'captchaSolve': '03A....8h',
'taskId': '73043008354',
'error': False,
'errorBody': None
"errorId":0,
"status":"ready",
"solution":{
"token":"P1_eyJ0eXAiOiJKV...1LDq89KyJ5A",
"respKey":"E0_eyJ0eXAiOiJK...y2w5_YbP8PGuJBBo",
"userAgent":"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.5614.0 Safari/537.36",
"gRecaptchaResponse":"P1_eyJ0eXAiOiJKV...1LDq89KyJ5A"
},
"cost":"0.00299",
"ip":"1.2.3.4",
"createTime":1692863536,
"endTime":1692863556,
"solveCount":1,
"taskId": 73243152973,
}
Returns:
Dict with full server response
Notes:
https://rucaptcha.com/api-rucaptcha#solving_hcaptcha
https://rucaptcha.com/api-docs/hcaptcha
"""
super().__init__(method=method, *args, **kwargs)

self.create_task_payload["task"].update({"pageurl": pageurl, "sitekey": sitekey})
self.create_task_payload["task"].update({"websiteURL": websiteURL, "websiteKey": websiteKey})

# check user params
if method not in HCaptchaEnm.list_values():
Expand Down

0 comments on commit dcea062

Please sign in to comment.