Guide
Task(Token)
Imperva

Incapsula/Imperva

TIP

Create the task with the createTask method and get the result with the getTaskResult method.

Note
  • We support reese84 sensors, utmvc and third-party captcha integrated
  • UserAgent needs to match. please use the one we support
  • It’s recommended to use a good TLS client in your workflow

The task type type is as follows

  • AntiImpervaTaskProxyless

Create Task

Create the task with the createTask.

Task Object Structure

reese84
PropertiesTypeRequiredDescription
typeStringYesAntiImpervaTaskProxyless
websiteURLStringYesThe website url
reeseScriptURLstringYesThe reese84 script URL, it usually has several dashes (-) and random words
scriptstringOptionalThe JavaScript obtained from doing a GET request to the reeseScriptURL
userAgentstringOptionalThe default is Chrome135, currently supports chrome135 - 137
utmvc
PropertiesTypeRequiredDescription
typeStringYesAntiImpervaTaskProxyless
websiteURLStringYesThe website url
scriptURLstringYesThe script URL of incapsula, it usually contains _Incapsula_Resource
isUtmvcBoolYesPlease set it to true
cookiesArrayYesEach cookie whose name begins with incap_ses_. Learn Using Cookies
userAgentstringOptionalThe default is Chrome135, currently supports chrome135 - 137
contains third-party captcha
PropertiesTypeRequiredDescription
typeStringYesAntiImpervaTask
websiteURLStringYesThe website url
htmlstringYesThe html of Incapsula when you request the target website
userAgentstringOptionalThe default is Chrome135, currently supports chrome135 - 137

Example Request and Response

// Example request
POST https://api.capsolver.com/createTask
Host: api.capsolver.com
Content-Type: application/json
Payload:
{
    "clientKey": "...",
    "task": {
        "type": "AntiImpervaTaskProxyLess",
        "script": "(function() {...",
        "reeseScriptUrl": "https://www.targetWebsite.com/s-weakes-Sir-Day-could-to-thy-them-breame-to-gre/1860025529848880788?s=xlD1csYd",
        "websiteURL": "https://www.targetWebsite.com/",
        "userAgent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/137.0.0.0 Safari/537.36"
    }
}


// Example Response
{
    "errorId": 0,
    "taskId": "...",
    "status": "ready",
    "solution": {
        "reese84Payload": "{\"solution\":{\"interrogation\":{\"p\":\"9pp4bv7Sp0073gA1xoN9Aoo...E\",\"st\":1744612535,\"sr\":3851658681,\"cr\":937075512,\"og\":2},\"version\":\"beta\"},\"old_token\":null,\"error\":null,\"performance\":{\"interrogation\":488}}",
        "userAgent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/137.0.0.0 Safari/537.36"
    }
}

Getting Results

After you have the taskId, you need to submit the taskId to retrieve the solution. Response structure is explained in getTaskResult.

Depending on the system load, you will get the results within the interval of 3s to 10s

Sample Code

# pip install curl_cffi
import re
from curl_cffi import requests
from urllib.parse import urlparse
 
api_key = "API_KEY"                         # TODO: your api key of capsolver
proxy = "127.0.0.1:1080"                      # TODO: your proxy
website_url = "https://www.targetWebsite.com/"  # TODO: your target website URL
default_user_agent = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/135.0.0.0 Safari/537.36'
 
parsed_url = urlparse(website_url)
website_host = "https://" + parsed_url.hostname
 
session = requests.Session(impersonate="chrome133a")
session.proxies = {
    "http": proxy,
    "https": proxy,
}
 
def view_website(cookie, user_agent):
    headers = {
        'accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7',
        'sec-ch-ua': '"Google Chrome";v="135", "Not-A.Brand";v="8", "Chromium";v="135"',
        'sec-ch-ua-mobile': '?0',
        'user-agent': user_agent,
        'sec-ch-ua-platform': '"Windows"',
        'sec-fetch-dest': 'document',
        'sec-fetch-mode': 'navigate',
        'sec-fetch-site': 'none',
        'sec-fetch-user': '?1',
        'upgrade-insecure-requests': '1',
        'accept-language': 'en-US,en;q=0.9',
        'priority': 'u=0, i',
    }
    if cookie:
        headers["cookie"] = "reese84=" + cookie
    res = session.get(website_url, headers=headers, verify=False)
    if res.status_code != 200:
        print("view website failed:", res.status_code, res.text)
        return
    reese_url = parse_reese_url_from_html(res.text)
    if not reese_url:
        if not cookie:
            print("reeseScriptUrl not found from website")
        else:
            print("succeed!")
        return
    print("get reeseScriptUrl from html:", reese_url)
    return reese_url
 
 
def get_reese84_script(reese_url, user_agent):
    headers = {
        'sec-ch-ua-platform': '"Windows"',
        'user-agent': user_agent,
        'sec-ch-ua': '"Google Chrome";v="135", "Not-A.Brand";v="8", "Chromium";v="135"',
        'sec-ch-ua-mobile': '?0',
        'accept': '*/*',
        'sec-fetch-site': 'same-origin',
        'sec-fetch-mode': 'no-cors',
        'sec-fetch-dest': 'script',
        'referer': website_url,
        'accept-language': 'en-US,en;q=0.9',
    }
    res = session.get(reese_url, headers=headers, verify=False)
    if res.status_code != 200:
        print('get reese84 script error:', res.status_code, res.text)
        return
    return res.text
 
 
def post_reese_payload(reese_url, payload, user_agent):
    if "?" in reese_url:
        reese_url = reese_url.split("?")[0]
    headers = {
        'sec-ch-ua-platform': '"Windows"',
        'user-agent': user_agent,
        'accept': 'application/json; charset=utf-8',
        'sec-ch-ua': '"Google Chrome";v="135", "Not-A.Brand";v="8", "Chromium";v="135"',
        'content-type': 'text/plain; charset=utf-8',
        'sec-ch-ua-mobile': '?0',
        'origin': website_host,
        'sec-fetch-site': 'same-origin',
        'sec-fetch-mode': 'cors',
        'sec-fetch-dest': 'empty',
        'referer': website_url,
        'accept-language': 'en-US,en;q=0.9',
        'priority': 'u=1, i',
    }
    resp = session.post(reese_url, headers=headers, data=payload, verify=False)
    if resp.status_code != 200:
        print("post reese84-payload failed:", resp.status_code, resp.text)
        return
    data = resp.json()
    token = data.get('token')
    if not token:
        print("post reese84-payload failed:", resp.status_code, resp.text)
        return
    return token
 
 
def parse_reese_url_from_html(html):
    # TODO: Set the rules for your target site
    result = re.search(r'scriptElement\.src = "(.*)"', html)
    if not result:
        return
    reese_url = result.group(1)
    if reese_url.startswith("/"):
        reese_url = website_host + reese_url
    return reese_url
 
 
def get_reese84_sensor(reese_url, page_url, script):
    payload = {
        "clientKey": api_key,
        "task": {
            "type": "AntiImpervaTaskProxyLess",
            "reeseScriptUrl": reese_url,
            "websiteURL": page_url,
            "script": script,
        }
    }
    res = requests.post("https://api.capsolver.com/createTask", json=payload)
    resp = res.json()
    task_id = resp.get("taskId")
    if not task_id:
        print("Failed to create task:", res.text)
        return
    print(f"Got taskId: {task_id} / Getting result...")
    while True:
        payload = {"clientKey": api_key, "taskId": task_id}
        res = requests.post("https://api.capsolver.com/getTaskResult", json=payload, verify=False)
        print(res.text)
        resp = res.json()
        status = resp.get("status")
        if status == "ready":
            return resp.get("solution", "")
        if status == "failed" or resp.get("errorId"):
            print("Solve failed! response:", res.text)
            return
 
def main():
    reese_url = view_website("", default_user_agent)
    if not reese_url:
        return
    script = get_reese84_script(reese_url, default_user_agent)
    if not script:
        return
    solution = get_reese84_sensor(reese_url, website_url, script)
    if not solution:
        return
    cookie = post_reese_payload(reese_url, solution["reese84Payload"], solution["userAgent"])
    if not cookie:
        return
    view_website(cookie, solution["userAgent"])
 
if __name__ == '__main__':
    main()