Guide
Task(Token)
Imperva Reese84

Incapsula/Imperva: solving reese84

TIP

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

Note
  • Currently our API only supports reese84 sensor, not cookie
  • Please use the userAgent returned by our API. Custom userAgent is not currently supported.
  • 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

PropertiesTypeRequiredDescription
typeStringYesAntiImpervaTaskProxyless
websiteURLStringYesThe website url
reeseScriptURLstringYesThe reese84 script URL (The URL usually has several dashes (-) and random words)

Example Request

POST https://api.capsolver.com/createTask
Host: api.capsolver.com
Content-Type: application/json
 
{
    "clientKey": "YOUR_API_KEY",
    "task": {
		"type": "AntiImpervaTaskProxyLess",
		"websiteURL": "https://www.targetSite.com/",
		"reeseScriptURL": "https://www.targetSite.com/s-weakes-Sir-Day-could-to-thy-them-breame-to-gre/12858188105179068283?s=H1eQbmt5"
    }
}

After you submit the task to us, you should receive in the response a ‘taskId’ if it’s successful. Please read errorCode: full list of errors if you didn’t receive the task id.

Example Response

{
    "errorId": 0,
    "errorCode": "",
    "errorDescription": "",
	"status": "idle",
    "taskId": "04dc7d73-7237-4836-95b8-85bbf91ba0c6"
}

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 1s to 3s

Example Request

POST https://api.capsolver.com/getTaskResult
Host: api.capsolver.com
Content-Type: application/json
 
{
    "clientKey": "YOUR_API_KEY",
    "taskId": "04dc7d73-7237-4836-95b8-85bbf91ba0c6"
}

Example Response

{
  "errorId": 0,
  "taskId": "04dc7d73-7237-4836-95b8-85bbf91ba0c6",
  "status": "ready",
  "solution": {
	"reese84Payload": "{\"solution\":{\"interrogation\":{\"p\":\"qt8DBWxcLIp......Dz1uvZg\",\"st\":1737605490,\"sr\":927471500,\"cr\":637462932,\"og\":2},\"version\":\"beta\"},\"old_token\":null,\"error\":null,\"performance\":{\"interrogation\":202}}\n",
	"userAgent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36"
  }
}

Sample Code

# pip install requests
import re
import requests
from urllib.parse import urlparse
 
api_key = "CAP-..."                         # TODO: your api key of capsolver
website_url = "https://www.targetSite.com/" # TODO: your target website url
proxy = "127.0.0.1:8888:name:pwd"           # TODO: your proxy
 
parsed_url = urlparse(website_url)
website_host = "https://" + parsed_url.hostname
session = requests.Session()
 
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 view_website(cookie):
    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="131", "Chromium";v="131", "Not_A Brand";v="24"',
        'sec-ch-ua-mobile': '?0',
        'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36',
        '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, proxies=format_proxy(proxy))
    reese_url = parse_reese_url_from_html(res.text)
    if not reese_url:
        print("reeseScriptUrl not found from website")
        return
    print("reeseScriptUrl:", reese_url)
    return reese_url
 
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="131", "Chromium";v="131", "Not_A Brand";v="24"',
        '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, proxies=format_proxy(proxy))
    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 format_proxy(px: str):
    if '@' not in px:
        sp = px.split(':')
        if len(sp) == 4:
            px = f'{sp[2]}:{sp[3]}@{sp[0]}:{sp[1]}'
 
    return {"https": f"http://{px}"}
 
def get_reese84_sensor(reese_url, page_url):
    payload = {
        "clientKey": api_key,
        "task": {
            "type": "AntiImpervaTaskProxyLess",
            "reeseScriptUrl": reese_url,
            "websiteURL": page_url
        }
    }
    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)
        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("")
    if not reese_url:
        return
    solution = get_reese84_sensor(reese_url, website_url)
    if not solution:
        return
    cookie = post_reese_payload(reese_url, solution["reese84Payload"], solution["userAgent"])
    if not cookie:
        return
    reese_url = view_website(cookie)
    if not reese_url:
        print("succeed!")
 
if __name__ == '__main__':
    main()