athlon1600 / php-captcha-solver
v2.0.0
2020-07-27 21:59 UTC
Requires
- ext-json: *
- athlon1600/php-curl-client: ^1.1
Requires (Dev)
This package is auto-updated.
Last update: 2024-08-28 09:44:20 UTC
README
适用于解决在抓取谷歌、YouTube 等使用 ReCaptcha 的网站时的验证码。
ReCaptcha V2
2captcha 的官方 PHP 库工作得不是很好,因此开发了此项目。
- https://2captcha.com/2captcha-api#recaptchav2new_post
- https://2captcha.com/blog/google-search-recaptcha
- https://2captcha.com/blog/update-google-recaptcha
<?php use CaptchaSolver\TwoCaptcha\Client; use CaptchaSolver\TwoCaptcha\InRequest; $captcha = new Client([ 'key' => 'API_KEY_GOES_HERE', 'proxy' => null // optional ]); $request = new InRequest([ 'googlekey' => '', 'pageurl' => '' ]); $response = $captcha->send($request); $id = $response->getResult(); sleep(45); $response = $captcha->getResult($id); $solution = $response->getSolution(); // or combine the two calls into one that polls automatically every 5 seconds and times out after 90 seconds: $response = $captcha->solveReCaptchaV2($request, 90);
$solution
现在应该包含一个类似于以下内容的 "solution" 令牌
03AGdBq24bamED8AtWElXZw9ceNn53tjN7fQ76dhyIbS_LS_5xWJuOXUb9ExnYUe_H3lvpKhZMX0Z7qmA-Ia9OBrbOu4eJYh2kosO89ZyTwADK8VrMXmQ8MD3NzaQeDg5jriopB9FrheDo7BemayGgqfJydtsRoJ_hg-RpDhzcwlUgLxJ9w4FwUd-IYBbGaMHp1wP4lbqMOpOaX21_D908LwZZgK2Dgc0TfJBTi_UL8r01sAYcvj2nouFG7JQCfXuj5LIzB8JL0Rxydig11sLayKIRbea66Jd_VkOj8h2xdC4NgDkY9OGkpRE
使用该解决方案作为 g-recaptcha-response
字段提交你获得的验证码表单,并包含其他相关表单字段,这样你就算完成了!
安装
composer require athlon1600/php-captcha-solver
测试
可以通过以下方式启动一个有用的迷你网络应用程序:
php -S localhost:8000 -t public
然后访问
http://localhost:8000/2captcha.php
已知问题
有时解决验证码并不能让你通过,而只是在结束时得到这条消息
因此,在这个时候,你除了等待一段时间不发送任何请求以外,别无他法,直到谷歌自动解除对你的 IP 地址的封锁。
其他事项
使 'g-recaptcha-response' 文本区域在页面上可见
document.getElementById('g-recaptcha-response').style = null;