Skip to main content

Solving CAPTCHA

Scraping Fish API allows you to solve CAPTCHAs in your scraping flow using the 2Captcha service. All CAPTCHA types covered by 2Captcha service work in Scraping Fish as well. To integrate this feature, you need to create an account and provide your 2Captcha API key in the request. CAPTCHA solving is a step in the JavaScript scenario, provided in JSON format in the js_scenario query parameter.

tip

Remember to encode js_scenario parameter as shown in the example below.

Example​

In this example, we will use the Google reCAPTCHA demo website: https://www.google.com/recaptcha/api2/demo.

First, we will solve the CAPTCHA using 2Captcha and then click on the #recaptcha-demo-submit button to submit the form and wait for navigation.

import requests
import json

payload = {
"api_key": "[your API key]",
"url": "https://www.google.com/recaptcha/api2/demo",
"js_scenario": json.dumps(
{"steps": [{"solve_captchas": "[2Cpatcha API key]"}, {"click_and_wait_for_navigation": "#recaptcha-demo-submit"}]}
),
}

response = requests.get("https://scraping.narf.ai/api/v1/", params=payload)
print(response.content)

Assuming that 2Captcha was able to solve the CAPTCHA on time, the response will contain the message: Verification Success... Hooray!.

<!DOCTYPE html>
<html dir="ltr">

<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width, user-scalable=yes">
<title>ReCAPTCHA demo</title>
<link rel="stylesheet" href="https://www.gstatic.com/recaptcha/releases/MuIyr8Ej74CrXhJDQy37RPBe/demo__ltr.css"
type="text/css">
</head>

<body>
<div class="recaptcha-success">Verification Success... Hooray!</div>
</body>

</html>
caution

Since this functionality depends on a third-party service, all requests containing the solve_captchas JS scenario step will be charged as successful, regardless of the result and response status code.