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

Function get_captcha

image_recognition_zhihu.py:44–65  ·  view source on GitHub ↗

获取验证码

(sessiona,headers)

Source from the content-addressed store, hash-verified

42
43
44def get_captcha(sessiona,headers):
45 ''' 获取验证码 '''
46
47 need_cap = False
48
49 while( need_cap is not True):
50 try:
51 sessiona.get('https://www.zhihu.com/signin',headers=headers) # 拿cookie:_xsrf
52 resp2 = sessiona.get('https://www.zhihu.com/api/v3/oauth/captcha?lang=cn',headers=headers) # 拿cookie:capsion_ticket
53 need_cap = json.loads(resp2.text)["show_captcha"] # {"show_captcha":false} 表示不用验证码
54 time.sleep( 0.5 + random.randint(1,9)/10 )
55 except Exception:
56 continue
57
58 try:
59 resp3 = sessiona.put('https://www.zhihu.com/api/v3/oauth/captcha?lang=cn',headers=headers) # 拿到验证码数据,注意是put
60 img_data = json.loads(resp3.text)["img_base64"]
61 except Exception:
62 return
63
64
65 return img_data
66
67def create_point( point_data, confidence ):
68 ''' 获得点阵 '''

Callers 1

boltingFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected