Bypassing HCaptcha Using YesCaptcha Service with Python
This article explains how to bypass HCaptcha verification by leveraging the YesCaptcha service, detailing the required API parameters, Python code for extracting captcha images via Selenium, converting them to Base64, creating a solving task, and handling the solution to automate the verification process.
HCaptcha is a widely used captcha service that protects websites from malicious bots; unlike Google reCaptcha, it is accessible for international sites. The article first introduces HCaptcha's user interaction, which may present a grid of images requiring selection based on a question.
Readers are guided to experience HCaptcha manually via the demo site https://democaptcha.com/demo-form-eng/hcaptcha.html, preferably in Chrome incognito mode, to understand the full verification flow.
To automate solving, the article recommends using the YesCaptcha platform. After registering at http://www.yescaptcha.com/ and obtaining a clientKey, users can create a HCaptchaClassification task through YesCaptcha's API.
The required API parameters are:
type : "HCaptchaClassification" (10 points)
queries : a list of Base64‑encoded images (without the data URI prefix)
question : the question ID extracted from the captcha challenge
Python code is provided to fetch the captcha images and question using Selenium, convert the images to Base64, and submit a task to YesCaptcha:
headers = {'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.127 Safari/537.36'}
def get_as_base64(url):
return base64.b64encode(requests.get(url).content)
def get_captcha_image_base64(data):
image_result = []
for d in data:
img_base64 = get_as_base64(d['datapoint_uri'])
img_base64 = img_base64.decode('utf-8')
image_result.append({'url': d['datapoint_uri'], 'task_key': d['task_key'], 'base64': img_base64})
return image_result
def create_task(question, queries):
url = 'https://api.yescaptcha.com/createTask'
data = {
"clientKey": clientKey,
"task": {
"type": "HCaptchaClassification",
"question": question,
"queries": queries,
}
}
r = requests.post(url, json=data, timeout=60)
return r.json()
if __name__ == '__main__':
with open('data.json', encoding='utf8') as f:
data = f.read()
data = json.loads(data)
question = data.get('requester_question', {}).get('zh')
tasklist = data.get('tasklist')
images = get_captcha_image_base64(tasklist)
queries = [d['base64'] for d in images]
result = create_task(question=question, queries=queries)
pprint.pprint(result)Running the script returns a JSON response containing a solution field with a list of booleans indicating which grid images should be selected, matching the order of the submitted queries. These results can be fed back to Selenium to programmatically click the appropriate images and submit the captcha.
The article concludes that, while the focus is on breaking HCaptcha, the surrounding Selenium automation steps are straightforward and well‑documented elsewhere.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Python Programming Learning Circle
A global community of Chinese Python developers offering technical articles, columns, original video tutorials, and problem sets. Topics include web full‑stack development, web scraping, data analysis, natural language processing, image processing, machine learning, automated testing, DevOps automation, and big data.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
