处理 CAPTCHA
为了在 A-Parser 中处理和解决验证码,我们实现了特殊的方法,允许使用以下爬虫工具将验证码发送到验证码识别服务进行识别:
Util::AntiGate - 识别包含字母/数字/单词的图片验证码
Util::ReCaptcha2 - 识别 Google ReCaptcha v2
Util::ReCaptcha3 - 识别 Google ReCaptcha v3
Util::hCaptcha - 识别 hCaptcha 验证码
Util::Turnstile - 识别 Cloudflare Turnstile 验证码
此外,使用 await this.parser.request() 方法也可以轻松识别 CAPTCHA。
例如,为 Google ReCaptcha v2 调用此方法如下所示:
await this.parser.request('Util::ReCaptcha2', this.conf.Util_ReCaptcha2_preset, {}, siteKey + ' ' + endPoint);
更多细节可以参考目录中的示例:通过 cyren.com 服务检查网站分类
await this.captcha.*
处理验证码
.recognize(preset, image, type[, overrides])
await this.captcha.recognize(preset, image, type, overrides) - 上传验证码进行识别
image- 用于识别的图片二进制数据preset- 指定
Util::AntiGate 的预设type指定为以下之一:'jpeg', 'gif', 'png'
结果将是一个包含以下字段的哈希:
answer- 图片中的文本id- 验证码 ID,以便后续通过.reportBad报告错误error- 文本错误(如果未设置 answer)
.recognizeFromUrl(preset, url[, overrides])
await this.captcha.recognizeFromUrl(preset, url, overrides) - 与前一个方法类似,但验证码将通过链接 (url) 自动下载,不使用代理
.reportBad(preset, id[, overrides])
await this.captcha.reportBad(preset, id, overrides) - 告知服务验证码识别错误
常用链接
🔗 ⏩ 创建 JS 爬虫工具。处理验证码
关于如何编写支持 AntiGate 以识别页面验证码的 JS 爬虫工具的视频
🔗 创建 JS 爬虫工具。处理验证码
关于如何编写支持 AntiGate 以识别页面验证码的 JS 爬虫工具的文章
🔗 通过 cyren.com 服务检查网站类别
在 JS 爬虫工具中实现连接 Util::ReCaptcha2 的示例