获取验证码
(sessiona,headers)
| 42 | |
| 43 | |
| 44 | def 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 | |
| 67 | def create_point( point_data, confidence ): |
| 68 | ''' 获得点阵 ''' |