From 16dbb5b9a174caa84f358394f169dd46c09cdf80 Mon Sep 17 00:00:00 2001 From: ngfchl Date: Fri, 2 Sep 2022 22:42:04 +0800 Subject: [PATCH] =?UTF-8?q?1.=20=E8=B0=83=E6=95=B4=E9=AA=8C=E8=AF=81?= =?UTF-8?q?=E7=A0=81OCR=E8=AF=86=E5=88=AB=E4=BB=A3=E7=A0=81=EF=BC=8C?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=B8=8D=E5=81=9C=E8=B0=83=E7=94=A8=E7=99=BE?= =?UTF-8?q?=E5=BA=A6API=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pt_site/UtilityTool.py | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/pt_site/UtilityTool.py b/pt_site/UtilityTool.py index f6b6478..e0eac12 100644 --- a/pt_site/UtilityTool.py +++ b/pt_site/UtilityTool.py @@ -211,12 +211,7 @@ class PtSpider: imagestring = ''.join(re.findall('[A-Za-z0-9]+', res2)).strip() print('天空验证码:', imagestring, len(imagestring)) # 识别错误就重来 - times = 0 - while len(imagestring) != 6 and times <= 5: - print('验证码长度:', len(imagestring), len(imagestring) == 6) - time.sleep(1) - self.ocr_captcha(img_url) - times += 1 + return CommonResponse.success( status=StatusCodeEnum.OK, data=imagestring, @@ -285,10 +280,19 @@ class PtSpider: print('验证码图片链接:', img_get_url) # 获取OCR识别结果 # imagestring = self.ocr_captcha(img_url=img_get_url) - ocr_result = self.ocr_captcha(img_get_url) - if ocr_result.code == StatusCodeEnum.OK.code: - imagestring = ocr_result.data - else: + times = 0 + # imagestring = '' + ocr_result = None + while times <= 5: + ocr_result = self.ocr_captcha(img_get_url) + if ocr_result.code == StatusCodeEnum.OK.code: + imagestring = ocr_result.data + print('验证码长度:', len(imagestring), len(imagestring) == 6) + if len(imagestring) == 6: + break + times += 1 + time.sleep(1) + if ocr_result.code != StatusCodeEnum.OK.code: return ocr_result # 组装请求参数 data = {