From 0dee6b1576f89ca316bba1edb0db041c8d716fdb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=AE=97=E5=91=BD=E7=B8=96=E5=AD=90?= <30351807+smxiazi@users.noreply.github.com> Date: Fri, 24 Jun 2022 22:48:04 +0800 Subject: [PATCH] Delete server.py --- server.py | 93 ------------------------------------------------------- 1 file changed, 93 deletions(-) delete mode 100644 server.py diff --git a/server.py b/server.py deleted file mode 100644 index d3422e2..0000000 --- a/server.py +++ /dev/null @@ -1,93 +0,0 @@ -#!/usr/bin/env python -# -*- conding:utf-8 -*- -from http.server import HTTPServer, BaseHTTPRequestHandler -import re,time,base64,os - -host = ('0.0.0.0', 8899) -count = 50 #保存多少个验证码及结果 - - -class Resquest(BaseHTTPRequestHandler): - def handler(self): - print("data:", self.rfile.readline().decode()) - self.wfile.write(self.rfile.readline()) - - def do_GET(self): - print(self.requestline) - if self.path != '/': - self.send_error(404, "Page not Found!") - return - with open('temp/log.txt', 'r') as f: - content = f.read() - data = 'xp_CAPTCHA

验证码识别:xp_CAPTCHA

author:算命縖子

%s'%(content) - self.send_response(200) - self.send_header('Content-type', 'text/html; charset=UTF-8') - self.end_headers() - self.wfile.write(data.encode()) - - def do_POST(self): - #print(self.headers) - #print(self.command) - text = '' - try: - if self.path != '/base64': - self.send_error(404, "Page not Found!") - return - img_name = time.time() - req_datas = self.rfile.read(int(self.headers['content-length'])) - req_datas = req_datas.decode() - base64_img = re.search('base64=(.*?)$',req_datas) - #print(base64_img.group(1)) #post base64参数的内容 - - with open("temp/%s.png"%img_name, 'wb') as f: - f.write(base64.b64decode(base64_img.group(1))) - f.close() - - #验证码识别 - sdk = muggle_ocr.SDK(model_type=muggle_ocr.ModelType.Captcha) - with open(r"temp/%s.png"%img_name, "rb") as f: - b = f.read() - text = sdk.predict(image_bytes=b) - print('\n'+text+'\n') #识别的结果 - - #保存最新count个的验证码及识别结果 - with open('temp/log.txt', 'r') as f: - data = "" - counts = 0 - content = f.read() - pattern = re.compile(r'.*?\n') - result1 = pattern.findall(content) - for i in result1: - counts += 1 - if counts >= count: break - data = data + i - - with open('temp/log.txt', 'w') as f: - f.write('\n'%(base64_img.group(1),text,time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(int(img_name))))+ data) - - #删除掉图片文件,以防占用太大的内存 - os.remove("temp/%s.png"%img_name) - except: - text= '0000' - print('\n识别失败!\n') - - if text =='': - text= '0000' - print('\n识别失败!\n') - - self.send_response(200) - self.send_header('Content-type', 'application/json') - self.end_headers() - self.wfile.write(text.encode('utf-8')) - -if __name__ == '__main__': - print('正在加载中请稍后……') - import muggle_ocr - os.makedirs('temp', exist_ok=True) - with open('temp/log.txt', 'w') as f: - pass - server = HTTPServer(host, Resquest) - print("Starting server, listen at: %s:%s" % host) - print('加载完成!请访问:http://127.0.0.1:%s' % host[1]) - print('github:https://github.com/smxiazi/NEW_xp_CAPTCHA\n\n') - server.serve_forever() \ No newline at end of file
验证码识别结果时间
%s%s