Solving hCaptchas using Anti-Captcha and Python Requests module

345 views Asked by At

I'm trying to solve the captcha that appears on https://eu.kith.com/international-checkout Here is a snippet of the relevant code. I've tried several different headers to no luck. Any help would be much appreciated. The response from https://gem-fs.global-e.com/1/Checkout/GetCartToken?merchantUniqueId=708 is always {"Success":false,"IsCaptcha":true}

site_key = 'b989d9e8-0d14-41a0-870f-97b5283ba67d'
site_url = 'https://eu.kith.com/pages/international-checkout'

# Create a task on the Anti-Captcha API
create_task_url = 'https://api.anti-captcha.com/createTask'
task_data = {
    'clientKey': api_key,
    'task': {
        'type': 'HCaptchaTaskProxyless',
        'websiteURL': site_url,
        'websiteKey': site_key
       

    }
}

response = s.post(create_task_url, json=task_data)
#print(response.json())  # checking response
task_id = response.json()['taskId']


# Retrieve the task result from the Anti-Captcha API
get_result_url = 'https://api.anti-captcha.com/getTaskResult'
result_data = {
    'clientKey': api_key,
    'taskId': task_id
}

# Poll the API until the task is completed
while True:
    time.sleep(5)  # Wait 5 seconds between requests
    result_response = s.post(get_result_url, json=result_data)
    result_json = result_response.json()

    if result_json['status'] == 'ready':
        hcaptcha_response = result_json['solution']['gRecaptchaResponse']
        print(result_json)
        #print(f"hCaptcha response: {hcaptcha_response}")
        break

#E0

#e0 = s.post("https://hcaptcha.com/checkcaptcha/b989d9e8-0d14-41a0-870f-97b5283ba67d/"+result_json["solution"]["respKey"], headers=e0_headers)

#print(e0.content)
#captcha_response_1 = json.loads(e0.content)["c"][0]["req"]
url = "https://gem-fs.global-e.com/1/Checkout/GetCartToken?merchantUniqueId=708"

headers = {
    #"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/112.0",
    "Accept": "*/*",
    "Accept-Language": "en-US,en;q=0.5",
    "Accept-Encoding": "gzip, deflate, br",
    "Content-Type": "application/x-www-form-urlencoded",
    "Origin": "https://eu.kith.com",
    "Referer": "https://eu.kith.com/",
    "Sec-Fetch-Dest": "empty",
    "Sec-Fetch-Mode": "cors",
    "Sec-Fetch-Site": "cross-site",
    "Te": "trailers",
}

data = {
    "MerchantCartToken": cartjs_token,
    "CountryCode": "SE",
    "CurrencyCode": "SEK",
    "CultureCode": "sv",
    "MerchantId": "708",
    "GetCartTokenUrl": "https%3A%2F%2Fgem-fs.global-e.com%2F1",
    "ClientCartContent": json.loads(cartjs.content),
    "AdditionalCartData": "%255B%255D",
    "CaptchaResponseToken": hcaptcha_response
}

rr = s.post(url, headers=headers, data=data)

# Print the response status code and content
print(rr.status_code)
print(rr.text)







checkout_page = s.get("https://eu.kith.com/pages/international-checkout")
with open("page.html", 'w', encoding='utf-8') as f:
    f.write(checkout_page.text)
checkout_soup = BeautifulSoup(checkout_page.content, "html.parser")
0

There are 0 answers