MCPcopy Index your code
hub / github.com/injetlee/Python / recognition_captcha

Function recognition_captcha

image_recognition_zhihu.py:13–41  ·  view source on GitHub ↗

识别验证码

(data)

Source from the content-addressed store, hash-verified

11
12
13def recognition_captcha(data):
14 ''' 识别验证码 '''
15
16 file_id = str(uuid.uuid1())
17 filename = 'captcha_'+ file_id +'.gif'
18 filename_png = 'captcha_'+ file_id +'.png'
19
20 if(data is None):
21 return
22 data = base64.b64decode(data.encode('utf-8'))
23 with open( filename ,'wb') as fb:
24 fb.write( data )
25
26 appid = 'appid' # 接入优图服务,注册账号获取
27 secret_id = 'secret_id'
28 secret_key = 'secret_key'
29 userid= 'userid'
30 end_point = TencentYoutuyun.conf.API_YOUTU_END_POINT
31
32 youtu = TencentYoutuyun.YouTu(appid, secret_id, secret_key, userid, end_point) # 初始化
33
34 # 拿到的是gif格式,而优图只支持 JPG PNG BMP 其中之一,这时我们需要 pip install Pillow 来转换格式
35 im = Image.open( filename)
36 im.save( filename_png ,"png")
37 im.close()
38
39 result = youtu.generalocr( filename_png , data_type = 0 , seq = '') # 0代表本地路径,1代表url
40
41 return result
42
43
44def get_captcha(sessiona,headers):

Callers 1

boltingFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected