CAPTCHA

# Integrate a Captcha solving service like 2Captcha.com

Axiom does not provide a CAPTCHA solving service in house, but it is possible to integrate with third party captcha solving services.

To do this, you'll need to register for a service, and add the required javascript to trigger the CAPTCHA solver.

We recommend using 2Captcha. Here's how to integrate that service into your automation:

Use the following code in 'Write JavaScript':

// Extract reCaptcha key
let xpath = '//div[@data-sitekey]'
let element = document.evaluate(xpath, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue
const gkey = element.getAttribute('data-sitekey')

const response = await fetch('https://2captcha.com/in.php' +
    '?key=INPUT-API-KEY-HERE' +
	'&method=userrecaptcha' +
	'&googlekey=' + gkey +
	'&pageurl=https://INPUT-PAGE-URL-HERE' +
	'&json=1' +
	'&header_acao=1')

const json = await response.json()
const request = json.request
console.log("Step 1: " + request)
return [[request]]

Then, add a 'Wait' Step in Axiom. You may need to wait for 1-3 minutes (60,000 - 180,000 milliseconds).

Finally, add a second 'Write JavaScript' step.

const requestID = '[code-data?*&0]';
console.log("Step 2: Request " + requestID)
const response = await fetch('https://2captcha.com/res.php' +
    '?key=db5808b34cd2cfe6a740613a75e2a8e3' +
	'&action=get' +
    '&id=' + requestID +
	'&json=1' +
    '&header_acao=1')

const json = await response.json()
const request = json.request
console.log("Step 2: Token " +  request)
const ta = document.getElementById("g-recaptcha-response")
ta.value = request