ThinkPHP验证码类库 think-captcha 图片验证码识别
所用项目及服务器 ThinkPHP:https://github.com/top-think/framework think-captcha:https://github.com/top-think/think-captcha captcha_trainer (训练):https://github.com/kerlomz/captcha_trainer captcha_platform (部署):https://github.com/kerlomz/captcha_platform MuggleOCR:https://pypi.org/project/muggle-ocr captcha_trainer 作者介绍:https://www.jianshu.com/p/80ef04b16efc 矩池云 GPU服务器:https://matpool.com/ captcha_trainer 使用过程 使用 ThinkPHP 调用 think-captcha 生成验证码 1 2 3 4 composer create-project topthink/think tp cd tp composer require topthink/think-captcha php think run 修改 think-captcha 源码,将验证码存储到 Session 在 vendor/topthink/think-captcha/src/Captcha.php:195 插入以下代码 1 Session::set('captcha', implode('', $code), ''); 在控制器内打印验证码 1 2 3 4 public function code() { $code = Session::get('captcha', ''); echo $code; } 使用 Python 抓取图片验证码样本,按照 captcha_trainer 默认规则重命名保存 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 import requests import threading import os import hashlib # def md5(s, salt=''): new_s = str(s) + salt m = hashlib.md5(new_s.encode()) return m.hexdigest() # def get_captcha(): session = requests.session() for i in range(0, 100000): try: content = session.get('http://x.com/captcha?'+str(i)) if content.status_code != 200: continue code = session.get('http://x.com/index/Home/code') if code.status_code != 200: continue filename = '{}_{}.png'.format(code.text, md5(content.content)) with open(os.path.join('captcha_images', filename), 'wb') as f: f.write(content.content) f.close() except Exception as e: print(str(e)) # for i in range(1, 20): t = threading.Thread(target=get_captcha, args=()) t.start() 租用矩池云 RTX 2080 Ti 的GPU服务器进行训练 ...