Arabic, Farsi, and Hebrew websites present CAPTCHAs with right-to-left (RTL) scripts that challenge standard OCR and text injection. Arabic characters connect differently based on position — initial, medial, final, or isolated forms — making image CAPTCHA recognition harder. Combined with RTL page layouts that affect element positioning, these sites need specific handling.
RTL CAPTCHA Challenges
| Challenge | Detail |
|---|---|
| Character connection | Arabic letters change shape based on adjacent characters |
| Right-to-left reading | Text in CAPTCHA reads right-to-left |
| Mixed direction | ANumbers and Latin text mix with Arabic (bidirectional) |
| Diacritical marks | Dots and marks above/below characters (شاين vs ساين) |
| RTL page layout | Form elements and CAPTCHA placement differ from LTR |
Python: Arabic Image CAPTCHA
import requests
import base64
import time
API_KEY = "YOUR_API_KEY"
SUBMIT_URL = "https://ocr.captchaai.com/in.php"
RESULT_URL = "https://ocr.captchaai.com/res.php"
def solve_arabic_captcha(image_path: str) -> str:
"""Solve an Arabic script image CAPTCHA."""
with open(image_path, "rb") as f:
image_b64 = base64.b64encode(f.read()).decode()
resp = requests.post(SUBMIT_URL, data={
"key": API_KEY,
"method": "base64",
"body": image_b64,
"language": 2, # Non-Latin character support
"json": 1,
}, timeout=30).json()
if resp.get("status") != 1:
raise RuntimeError(f"Submit: {resp.get('request')}")
task_id = resp["request"]
for _ in range(24):
time.sleep(5)
poll = requests.get(RESULT_URL, params={
"key": API_KEY, "action": "get", "id": task_id, "json": 1,
}, timeout=15).json()
if poll.get("request") == "CAPCHA_NOT_READY":
continue
if poll.get("status") == 1:
return poll["request"]
raise RuntimeError(f"Solve: {poll.get('request')}")
raise RuntimeError("Timeout")
def solve_arabic_captcha_from_url(session: requests.Session,
captcha_url: str) -> str:
"""Download and solve an Arabic CAPTCHA from a URL."""
resp = session.get(captcha_url, timeout=15)
image_b64 = base64.b64encode(resp.content).decode()
submit = requests.post(SUBMIT_URL, data={
"key": API_KEY,
"method": "base64",
"body": image_b64,
"language": 2,
"json": 1,
}, timeout=30).json()
if submit.get("status") != 1:
raise RuntimeError(f"Submit: {submit.get('request')}")
task_id = submit["request"]
for _ in range(24):
time.sleep(5)
poll = requests.get(RESULT_URL, params={
"key": API_KEY, "action": "get", "id": task_id, "json": 1,
}, timeout=15).json()
if poll.get("request") == "CAPCHA_NOT_READY":
continue
if poll.get("status") == 1:
return poll["request"]
raise RuntimeError(f"Solve: {poll.get('request')}")
raise RuntimeError("Timeout")
# --- RTL-aware form submission ---
def submit_form_with_arabic_captcha(
form_url: str,
captcha_url: str,
form_data: dict,
captcha_field: str = "captcha",
) -> requests.Response:
"""Complete an Arabic website form with CAPTCHA."""
session = requests.Session()
session.headers.update({
"Accept-Language": "ar-SA,ar;q=0.9",
"Content-Type": "application/x-www-form-urlencoded; charset=UTF-8",
})
# Load the form page to establish session
session.get(form_url, timeout=15)
# Solve the CAPTCHA
captcha_text = solve_arabic_captcha_from_url(session, captcha_url)
print(f"Arabic CAPTCHA solved: {captcha_text}")
# Submit with the solved text
form_data[captcha_field] = captcha_text
response = session.post(form_url, data=form_data, timeout=30)
return response
# --- Usage ---
# Simple Arabic image CAPTCHA
text = solve_arabic_captcha("arabic_captcha.png")
print(f"Arabic text: {text}")
# Form submission on Arabic site
response = submit_form_with_arabic_captcha(
form_url="https://example.sa/registration",
captcha_url="https://example.sa/captcha/generate",
form_data={
"name": "اسم المستخدم",
"email": "user@example.com",
},
)
JavaScript: Arabic and RTL CAPTCHA
const API_KEY = "YOUR_API_KEY";
const SUBMIT_URL = "https://ocr.captchaai.com/in.php";
const RESULT_URL = "https://ocr.captchaai.com/res.php";
const fs = require("fs");
async function solveArabicCaptcha(imagePath) {
const imageB64 = fs.readFileSync(imagePath, "base64");
const body = new URLSearchParams({
key: API_KEY,
method: "base64",
body: imageB64,
language: "2",
json: "1",
});
const resp = await (await fetch(SUBMIT_URL, { method: "POST", body })).json();
if (resp.status !== 1) throw new Error(`Submit: ${resp.request}`);
const taskId = resp.request;
for (let i = 0; i < 24; i++) {
await new Promise((r) => setTimeout(r, 5000));
const url = `${RESULT_URL}?key=${API_KEY}&action=get&id=${taskId}&json=1`;
const poll = await (await fetch(url)).json();
if (poll.request === "CAPCHA_NOT_READY") continue;
if (poll.status === 1) return poll.request;
throw new Error(`Solve: ${poll.request}`);
}
throw new Error("Timeout");
}
// Inject CAPTCHA token into RTL page with Playwright
async function solveAndInjectRTL(page) {
// RTL pages may position the CAPTCHA differently
const captchaImg = await page.locator("img[id*='captcha'], img[class*='captcha']");
const imgSrc = await captchaImg.getAttribute("src");
// Download the image
const buffer = await (await fetch(imgSrc)).arrayBuffer();
const imageB64 = Buffer.from(buffer).toString("base64");
// Solve
const body = new URLSearchParams({
key: API_KEY, method: "base64", body: imageB64,
language: "2", json: "1",
});
const resp = await (await fetch(SUBMIT_URL, { method: "POST", body })).json();
if (resp.status !== 1) throw new Error(`Submit: ${resp.request}`);
const taskId = resp.request;
for (let i = 0; i < 24; i++) {
await new Promise((r) => setTimeout(r, 5000));
const url = `${RESULT_URL}?key=${API_KEY}&action=get&id=${taskId}&json=1`;
const poll = await (await fetch(url)).json();
if (poll.request === "CAPCHA_NOT_READY") continue;
if (poll.status === 1) {
// Fill the input — RTL input handles text direction automatically
await page.locator("input[name*='captcha']").fill(poll.request);
return poll.request;
}
throw new Error(`Solve: ${poll.request}`);
}
}
// Usage
const text = await solveArabicCaptcha("arabic_captcha.png");
console.log(`Arabic text: ${text}`);
RTL Scripts Supported
| Script | Languages | Example characters |
|---|---|---|
| Arabic | Arabic, Urdu, Pashto | عربي - أبجدية |
| Farsi/Persian | Farsi | فارسی - حروف |
| Hebrew | Hebrew | עברית - אותיות |
Troubleshooting
| Issue | Cause | Fix |
|---|---|---|
| Arabic text reversed in output | Client displaying RTL text as LTR | Wrap output in \u202B (RTL embedding) or use RTL-aware display |
| Diacritical marks missing | Low-resolution image | Use higher-resolution CAPTCHA images |
| Bidirectional text (Arabic+numbers) jumbled | BiDi algorithm applied inconsistently | Handle directional characters explicitly with Unicode markers |
| Form submission fails with Arabic input | Encoding mismatch | Use charset=UTF-8 in Content-Type header |
| CAPTCHA position differs from expected | RTL layout mirrors element positions | Use CSS selectors rather than position-based detection |
FAQ
Does CaptchaAI handle connected Arabic script?
Yes. Arabic characters connect when adjacent — the same letter looks different depending on its position in a word. CaptchaAI's Image/OCR solver recognizes connected Arabic script including initial, medial, final, and isolated letter forms.
How do I handle Farsi CAPTCHAs vs. Arabic CAPTCHAs?
Both use the Arabic script but with additional characters (like پ, چ, ژ, گ in Farsi). Use language=2 for both. CaptchaAI recognizes the extended character set automatically.
Do RTL page layouts affect CAPTCHA detection?
RTL layouts mirror the page — forms and CAPTCHAs may appear on opposite sides compared to LTR pages. Use CSS selectors or IDs to locate CAPTCHA elements rather than relying on visual position.
Next Steps
Solve CAPTCHAs on Arabic and RTL websites — get your CaptchaAI API key and handle any RTL character set.
Related guides:
Discussions (0)
Join the conversation
Sign in to share your opinion.
Sign InNo comments yet.