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

Function bolting

image_recognition_zhihu.py:93–152  ·  view source on GitHub ↗

筛选把握大的进行验证

(k_low,k_hi,k3_confidence)

Source from the content-addressed store, hash-verified

91 return result
92
93def bolting(k_low,k_hi,k3_confidence):
94 ''' 筛选把握大的进行验证 '''
95
96 start = time.time()
97
98 is_success = False
99 while(is_success is not True):
100
101 points_len = 1
102 angle = -20
103 img_ko = []
104
105 while(points_len != 21 or angle < k_low or angle > k_hi ):
106 img_data = get_captcha(sessiona,headers)
107 img_ko = recognition_captcha(img_data)
108
109 ## json.dumps 序列化时对中文默认使用的ascii编码.想输出真正的中文需要指定ensure_ascii=False
110 # img_ko_json = json.dumps(img_ko , indent =2 ,ensure_ascii=False )
111 # img_ko_json = img_ko_json.encode('raw_unicode_escape') ## 因为python3的原因,也因为优图自身的原因,此处要特殊处理
112
113 # with open( "json.txt" ,'wb') as fb:
114 # fb.write( img_ko_json )
115
116 try:
117 points_len = len(img_ko['items'][0]['itemstring'])
118 angle = img_ko['angle']
119 except Exception:
120 points_len = 1
121 angle = -20
122 continue
123
124 # print(img_ko_json.decode('utf8')) ## stdout用的是utf8,需转码才能正常显示
125 # print('-'*50)
126
127 input_text = create_point( img_ko ,k3_confidence )
128 if(type(input_text) == type([])):
129 continue
130
131 data = {
132 "input_text":input_text
133 }
134
135 # 提交过快会被拒绝,{"code":120005,"name":"ERR_VERIFY_CAPTCHA_TOO_QUICK"} ,假装思考5秒钟
136 time.sleep( 4 + random.randint(1,9)/10 )
137 try:
138 resp5 = sessiona.post('https://www.zhihu.com/api/v3/oauth/captcha?lang=cn',data,headers=headers)
139 except Exception:
140 continue
141
142 print("angle: "+ str(angle) )
143 print(BeautifulSoup(resp5.content ,'html.parser')) # 如果验证成功,会回应{"success":true},开心
144 print('-'*50)
145 try:
146 is_success = json.loads(resp5.text)["success"]
147 except KeyError:
148 continue
149
150 end = time.time()

Callers 1

Calls 3

recognition_captchaFunction · 0.85
create_pointFunction · 0.85
get_captchaFunction · 0.70

Tested by

no test coverage detected