تقدم اختبارات CAPTCHA لصورة الشبكة صورة كبيرة مقسمة إلى شبكة (عادةً 3 × 3 أو 4 × 4) وتطلب من المستخدمين تحديد خلايا مطابقة للوصف. بينما يستخدم reCAPTCHA هذا التنسيق، تستخدم العديد من المواقع اختبارات الشبكة المخصصة التي لا تشكل جزءًا من نظام Google.
يغطي هذا الدليل حل تحديات الصور الشبكية غير reCAPTCHA باستخدام نقطة النهاية method=grid الخاصة بـ CaptchaAI.
المتطلبات
| البند | القيمة |
|---|---|
| مفتاح CaptchaAI API | منcaptchaai.com |
| صورة الشبكة | لقطة شاشة أو base64 للشبكة الكاملة |
| اللغة | بايثون 3.7+ أو Node.js 14+ |
الخطوة 1: التقاط صورة الشبكة
الطريقة أ: لقطة شاشة لعنصر captcha
from selenium import webdriver
from selenium.webdriver.common.by import By
driver = webdriver.Chrome()
driver.get("https://example.com/protected-form")
# Screenshot just the captcha container
captcha_element = driver.find_element(By.CSS_SELECTOR, "#captcha-container")
captcha_element.screenshot("captcha_grid.png")
الطريقة ب: استخراج الصورة من سمة src
import base64
import requests
captcha_img = driver.find_element(By.CSS_SELECTOR, ".grid-captcha img")
src = captcha_img.get_attribute("src")
if src.startswith("data:image"):
image_b64 = src.split(",")[1]
else:
image_data = requests.get(src).content
image_b64 = base64.b64encode(image_data).decode()
الخطوة 2: أرسل الصورة إلى CaptchaAI
استخدام تحميل الملفات (Python)
import requests
import time
API_KEY = "YOUR_API_KEY"
with open("captcha_grid.png", "rb") as f:
response = requests.post("https://ocr.captchaai.com/in.php",
data={
"key": API_KEY,
"method": "post",
"recaptcha": 1,
"json": 1
},
files={"file": f}
)
data = response.json()
task_id = data["request"]
print(f"Task: {task_id}")
باستخدام base64 (بايثون)
response = requests.post("https://ocr.captchaai.com/in.php", data={
"key": API_KEY,
"method": "post",
"body": image_b64,
"recaptcha": 1,
"json": 1
})
task_id = response.json()["request"]
Node.js
const axios = require('axios');
const fs = require('fs');
async function submitGridCaptcha(imagePath) {
const imageB64 = fs.readFileSync(imagePath).toString('base64');
const { data } = await axios.post('https://ocr.captchaai.com/in.php', null, {
params: {
key: 'YOUR_API_KEY',
method: 'post',
body: imageB64,
recaptcha: 1,
json: 1
}
});
return data.request;
}
الخطوة 3: استطلاع للحل
def get_grid_solution(task_id):
for _ in range(30):
time.sleep(5)
result = requests.get("https://ocr.captchaai.com/res.php", params={
"key": API_KEY,
"action": "get",
"id": task_id,
"json": 1
}).json()
if result.get("status") == 1:
return result["request"]
if result.get("request") != "CAPCHA_NOT_READY":
raise Exception(f"Error: {result['request']}")
raise Exception("Timeout")
solution = get_grid_solution(task_id)
print(f"Solution: {solution}")
# Returns click coordinates or cell indices
الخطوة 4: تطبيق الحل
انقر حسب فهرس الخلية
# If solution returns cell indices (e.g., "2,5,6")
selected = [int(i) for i in solution.split(",")]
cells = driver.find_elements(By.CSS_SELECTOR, ".grid-cell")
for idx in selected:
cells[idx - 1].click()
time.sleep(0.2)
driver.find_element(By.CSS_SELECTOR, ".verify-button").click()
انقر حسب الإحداثيات
from selenium.webdriver.common.action_chains import ActionChains
# If solution returns coordinates (e.g., "x=120,y=80;x=250,y=200")
captcha_element = driver.find_element(By.CSS_SELECTOR, "#captcha-container")
actions = ActionChains(driver)
for coord in solution.split(";"):
parts = dict(p.split("=") for p in coord.split(","))
x, y = int(parts["x"]), int(parts["y"])
actions.move_to_element_with_offset(captcha_element, x, y).click()
actions.perform()
استكشاف الأخطاء وإصلاحها
| خطأ | السبب | إصلاح |
|---|---|---|
ERROR_WRONG_FILE_EXTENSION |
تنسيق الصورة غير صالح | استخدم PNG أو JPEG؛ تحقق من صلاحية Base64 |
ERROR_CAPTCHA_UNSOLVABLE |
الصورة صغيرة جدًا أو غير واضحة | التقط بدقة كاملة |
| تم تحديد خلايا خاطئة | تنسيق الحل غير متطابق | تحقق مما إذا كان الحل هو المؤشرات مقابل الإحداثيات |
ERROR_TOO_BIG_CAPTCHA_FILESIZE |
الصورة تتجاوز الحد الأقصى للحجم | تغيير الحجم إلى أقل من 600 كيلو بايت |
مثال كامل قابل للتشغيل
هل تحتاج إلى مشروع عمل كامل مع إعداد البيئة والاستقصاء وإعادة المحاولة ومعالجة الأخطاء؟
راجع المثال الكامل القابل للتشغيل على GitHub →
الأسئلة الشائعة
متى يجب علي استخدام حل الشبكة مقابل حل الرمز المميز؟
استخدم حل الرمز المميز (method=userrecaptcha) لتحديات reCAPTCHA القياسية - فهو أبسط وأكثر موثوقية. استخدم حل الشبكة (method=post مع recaptcha=1) لتحديات الشبكة غير reCAPTCHA أو شبكات الصور المستقلة.
ما هي أحجام الشبكة المدعومة؟
يتعامل CaptchaAI مع تخطيطات الشبكة 3×3 و4×4 وغير القياسية. يتم تحليل الصورة ككل، بغض النظر عن بنية الشبكة.
ما مدى دقة حل الشبكة؟
الدقة تعتمد على جودة الصورة. الصور الواضحة عالية الدقة تحقق أفضل النتائج. متوسط وقت الحل هو 15-30 ثانية.
هل يمكنني حل الشبكات الديناميكية حيث يتغير البلاط؟
بالنسبة لشبكات reCAPTCHA الديناميكية (حيث يتم استبدال المربعات التي تم النقر عليها)، استخدم طريقة الرمز المميز (method=userrecaptcha). تحل طريقة الشبكة صورة ثابتة واحدة.