In questo articolo abbiamo cercato di rispondere a tutte le domande principali. Il primo passo per risolvere il problema è capire quale sistema di protezione viene utilizzato. A questo scopo puoi consultare l’elenco dei captcha e dei sistemi di protezione antibot più diffusi, dove trovi esempi visivi e caratteristiche chiave che ti aiutano a identificare rapidamente con cosa hai a che fare.
Se scopri che sul tuo sito viene utilizzato MTCaptcha, il passo successivo è analizzarne più nel dettaglio le proprietà e il funzionamento. In questo stesso articolo puoi anche studiare la guida all’integrazione di MTCaptcha, per comprendere a fondo come opera sul tuo sito. Questo ti permetterà non solo di capire la protezione attuale, ma anche di pianificarne correttamente la manutenzione.
Quando testi form che includono MTCaptcha devi spesso verificare che la captcha funzioni e sia integrata correttamente.
Puoi verificare manualmente la captcha inserita nel tuo sito.
Per la risoluzione automatica puoi usare strumenti come CapMonster Cloud, che accetta i parametri della captcha, li elabora sui propri server e restituisce un token pronto all'uso. Inserisci quel token nel form per superare il controllo senza intervento dell'utente.
Lavorare con CapMonster Cloud via API di solito prevede i seguenti passaggi:
type - MTCaptchaTask
websiteURL - Indirizzo della pagina principale in cui viene risolto il captcha.
websiteKey - Chiave MTcaptcha, trasmessa nella richiesta come parametro “sk”.
pageAction - Il parametro action viene inviato nella richiesta come “act” e viene visualizzato durante la validazione del token. Indicatelo solo se il valore differisce da quello predefinito – %24.
isInvisible - Indicate true se il captcha è invisibile, cioè ha un campo nascosto per la conferma. Se viene sospettata attività di bot, viene eseguito un controllo aggiuntivo.
https://api.capmonster.cloud/createTask{
"clientKey": "API_KEY",
"task":
{
"type": "MTCaptchaTask",
"websiteURL": "https://www.example.com",
"websiteKey": "MTPublic-abCDEFJAB",
"isInvisible": false,
"pageAction": "login"
}
}
{
"errorId":0,
"taskId":407533072
}https://api.capmonster.cloud/getTaskResult{
"clientKey":"API_KEY",
"taskId": 407533072
}
{
"errorId": 0,
"errorCode": null,
"errorDescription": null,
"solution": {
"token": "v1(155506dc,c8c2e356,MTPublic-abCDEFJAB,70f03532a53...5FSDA**)"
},
"status": "ready"
}
// npm install playwright @zennolab_com/capmonstercloud-client
import { chromium } from 'playwright';
import { CapMonsterCloudClientFactory, ClientOptions, MTCaptchaRequest } from '@zennolab_com/capmonstercloud-client';
const API_KEY = 'YOUR_API_KEY';
const TARGET_URL = 'https://example.com';
async function main() {
const browser = await chromium.launch({ headless: false });
const context = await browser.newContext();
const page = await context.newPage();
let websiteKey = null;
page.on('request', request => {
const url = request.url();
if (url.startsWith('https://service.mtcaptcha.com/mtcv1/api/getchallenge.json')) {
const params = new URL(url).searchParams;
const sk = params.get('sk');
if (sk) {
websiteKey = sk;
console.log('Extracted websiteKey (sk):', websiteKey);
}
}
});
await page.goto(TARGET_URL, { waitUntil: 'networkidle' });
if (!websiteKey) {
console.error('Failed to extract websiteKey (sk) from the page');
await browser.close();
return;
}
const client = CapMonsterCloudClientFactory.Create(
new ClientOptions({ clientKey: API_KEY })
);
const mtcaptchaRequest = new MTCaptchaRequest({
websiteURL: TARGET_URL,
websiteKey: websiteKey,
isInvisible: false,
pageAction: 'login'
});
// Risoluzione captcha
const result = await client.Solve(mtcaptchaRequest);
const verifiedToken = typeof result?.solution?.value === 'string'
? result.solution.value
: JSON.stringify(result.solution.token);
console.log('VerifiedToken:', verifiedToken);
// Inseriamo il token e inviamo il form (sostituire con il selettore corretto)
await page.evaluate((token) => {
const input = document.querySelector('#mtcaptcha-verifiedtoken-1');
if (input) input.value = token;
}, verifiedToken);
console.log('Token inserted into input');
// await page.click('button[type="submit"]');
await page.waitForTimeout(5000);
await browser.close();
}
main().catch(err => {
console.error('An error occurred:', err);
});1. Registrati o accedi al tuo account MTCaptcha.
2. Dopo la registrazione, aggiungi il tuo sito. Riceverai due chiavi.
Esempio:
3. Configura il client MTCaptcha:
Inserisci il codice nel <head> della pagina.
Sostituisci <YOUR SITE KEY> con la tua Site Key ottenuta dal pannello MTCaptcha.
<head>
<script>
var mtcaptchaConfig = {
sitekey: "<YOUR SITE KEY>"
};
(function() {
var mt_service = document.createElement('script');
mt_service.async = true;
mt_service.src = 'https://service.mtcaptcha.com/mtcv1/client/mtcaptcha.min.js';
(document.head || document.body).appendChild(mt_service);
var mt_service2 = document.createElement('script');
mt_service2.async = true;
mt_service2.src = 'https://service2.mtcaptcha.com/mtcv1/client/mtcaptcha2.min.js';
(document.head || document.body).appendChild(mt_service2);
})();
</script>
</head>
Aggiungi il contenitore captcha nel <body>
Dove vuoi visualizzare il captcha (ad esempio all'interno di un form):
<div class="mtcaptcha"></div>Il widget si caricherà automaticamente.
Puoi usare i SDK e plugin pronti per una rapida integrazione:
MTCaptcha offre anche una comoda pagina demo dove puoi testare e configurare la protezione prima di implementarla sul tuo sito.
4. Lato server. Ottieni Verified-Token sul client.
Tramite campo nascosto nel form:
<input type="hidden" name="mtcaptcha-verifiedtoken" />Oppure tramite JS:
mtcaptcha.getVerifiedToken() / mtcaptchaVerifiedCallback(status)Invia il token al server insieme al form o alla richiesta.
Verifica il token tramite API (verifica server-side):
GET https://service.mtcaptcha.com/mtcv1/api/checktoken?privatekey=<PRIVATE_KEY>&token=<TOKEN>URL alternativo per server con firewall:
https://service2.mtcaptcha.com/mtcv1/api/checktokenElabora la risposta:
success: true → captcha superato, continua elaborazione.
{
"success": true,
"tokeninfo": {
"v": "1.0",
"code": 201,
"codeDesc": "valid:captcha-solved",
"tokID": "ae1e60a1e249c217cb7b05c4dba8dd0d",
"timestampSec": 1552185983,
"timestampISO": "2019-03-10T02:46:23Z",
"hostname": "some.example.com",
"isDevHost": false,
"action": "",
"ip": "10.10.10.10"
}
}success: false → errore (token scaduto, riutilizzato, ecc.)
const { MTCaptcha } = require('mtcaptcha');
const PRIVATE_KEY = 'YOUR_PRIVATE_KEY';
const tokenFromClient = 'TOKEN';
const mt = new MTCaptcha(PRIVATE_KEY, tokenFromClient);
mt.verify((result) => {
if (result.success) {
console.log('Captcha passed!', result.tokeninfo);
} else {
console.error('Captcha failed:', result.fail_codes || result.error);
}
});Per uno studio dettagliato delle funzionalità MTCaptcha — personalizzazione del widget, configurazione client/server, integrazione con framework e altri aspetti — consulta la documentazione ufficiale.
Se ti è capitato un sito con un captcha o un altro sistema di protezione già installato e senza accesso al codice, nessun problema! È piuttosto facile capire quale tecnologia viene utilizzata. Per verificare che tutto funzioni correttamente, puoi usare il servizio di riconoscimento CapMonster Cloud in un ambiente di test isolato, così da assicurarti che il meccanismo di elaborazione dei token e la logica di verifica funzionino correttamente.
Nel caso di MTCaptcha, è sufficiente individuare il sistema, analizzarne il comportamento e assicurarsi che la protezione funzioni correttamente. Nell’articolo abbiamo mostrato come riconoscere MTCaptcha e dove trovare le istruzioni per la sua integrazione o riconfigurazione, in modo da poter mantenere la protezione in modo affidabile e controllarne il funzionamento.