From 85400a3fad66bf23d1b2c3439c11da1d3acb1f13 Mon Sep 17 00:00:00 2001 From: ngfchl Date: Thu, 8 Sep 2022 12:44:34 +0800 Subject: [PATCH] =?UTF-8?q?1.=20=E5=88=A0=E9=99=A4=E5=86=97=E4=BD=99?= =?UTF-8?q?=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pt_site/UtilityTool.py | 33 +++------------------------------ 1 file changed, 3 insertions(+), 30 deletions(-) diff --git a/pt_site/UtilityTool.py b/pt_site/UtilityTool.py index 6e447c9..e8edc1b 100644 --- a/pt_site/UtilityTool.py +++ b/pt_site/UtilityTool.py @@ -209,7 +209,7 @@ class PtSpider: res2 = res1.get('words_result')[0].get('words') # 去除杂乱字符 imagestring = ''.join(re.findall('[A-Za-z0-9]+', res2)).strip() - print('天空验证码:', imagestring, len(imagestring)) + print('百度OCR天空验证码:', imagestring, len(imagestring)) # 识别错误就重来 return CommonResponse.success( @@ -219,40 +219,12 @@ class PtSpider: except Exception as e: print(str(e)) # raise - self.send_text('OCR识别失败:' + str(e)) + self.send_text('百度OCR识别失败:' + str(e)) return CommonResponse.error( status=StatusCodeEnum.OCR_ACCESS_ERR, msg=StatusCodeEnum.OCR_ACCESS_ERR.errmsg + str(e) ) - """ paddleocr本地识别出问题,暂时放弃 - def paddle_ocr(self, img_src: str): - # paddle_ocr调用识别验证码,本地识别没有合适的结果再向百度OCR请求 - paddle = PaddleOCR(use_angle_cls=True, lang='en') - try: - # result = paddle.ocr(img_src, cls=True) - result = paddle.ocr(img_src) - times = 0 - print(result) - for line in result: - code = line[-1][0].strip() - print(code) - if len(code) != 6 and times <= 5: - times += 1 - # print(times) - self.paddle_ocr(img_src) - # else: - if len(code) == 6: - return CommonResponse.success( - data=code - ) - # 如果本地OCR失败就是用百度OCR - return self.ocr_captcha(img_url=img_src) - except Exception as e: - print(str(e)) - return CommonResponse.error(msg='本地OCR识别失败!' + str(e)) - """ - def sign_in_hdsky(self, my_site: MySite, captcha=False): """HDSKY签到""" site = my_site.site @@ -284,6 +256,7 @@ class PtSpider: # imagestring = '' ocr_result = None while times <= 5: + # ocr_result = self.ocr_captcha(img_get_url) ocr_result = self.ocr_captcha(img_get_url) if ocr_result.code == StatusCodeEnum.OK.code: imagestring = ocr_result.data