def _get_captcha(self, lang: str): """ 请求验证码的 API 接口,无论是否需要验证码都需要请求一次 如果需要验证码会返回图片的 base64 编码 根据 lang 参数匹配验证码,需要人工输入 :param lang: 返回验证码的语言(en/cn) :return: 验证码的 POST 参数 """ api = 'https://www.zhihu.com/api/v3/oauth/captcha?lang={}'.format(lang) resp = self.session.get(api) show_captcha = re.search(r'true', resp.text) if show_captcha: put_resp = self.session.put(api) json_data = json.loads(put_resp.text) img_base64 = json_data['img_base64'].replace(r'\n', '') img_data = base64.b64decode(img_base64) self.logger.info('使用超级鹰识别验证码...') ok, result = image_to_text(img_data) if ok: self.logger.info('成功识别验证码! ') # 这里必须先把参数 POST 验证码接口 time.sleep(1) res = self.session.post(api, data={ 'input_text': result }).json() if 'success' in res.keys(): return result raise Exception('验证码 post 失败: {}'.format( res['error']['message'])) raise Exception('验证码识别失败: ', result) raise Exception('获取验证码失败! ')
def _get_verifycode(self): captcha_url = 'http://icode.renren.com/getcode.do?t=web_login&rnd=0.28838133194471105' img_data = self.session.get(captcha_url).content self.logger.info('使用超级鹰识别验证码...') ok, result = image_to_text(img_data) if ok: self.logger.info('成功识别验证码!') return result raise Exception('验证码识别失败: ', result)
def _get_verifycode(self, pcid): captcha_url = f'https://login.sina.com.cn/cgi/pin.php?r=16343619&s=0&p={pcid}' img_data = self.session.get(captcha_url).content self.logger.info('使用超级鹰识别验证码...') ok, result = image_to_text(img_data) if ok: self.logger.info('成功识别验证码!') return result raise Exception('验证码识别失败: ', result)
def _get_verifycode(self): captcha_url = 'https://www.qichamao.com/usercenter/varifyimage?' img_data = self.session.get(captcha_url).content self.logger.info('使用超级鹰识别验证码...') ok, result = image_to_text(img_data) if ok: self.logger.info('成功识别验证码!') return result raise Exception('验证码识别失败: ', result)
def _get_verifycode(self): timestamp = int(time.time() * 1000) captcha_url = f'https://api.qimai.cn/account/getVerifyCodeImage?{timestamp}' img_data = self.session.get(captcha_url).content self.logger.info('使用超级鹰识别验证码...') ok, result = image_to_text(img_data) if ok: self.logger.info('成功识别验证码!') return result raise Exception('验证码识别失败: ', result)
def _get_verifycode(self): captcha_url = 'https://login.anjuke.com/general/captcha?h=45×tamp={}'.format( int(time.time()) * 1000) img_data = self.session.get(captcha_url).content self.logger.info('使用超级鹰识别验证码...') ok, result = image_to_text(img_data) if ok: self.logger.info('成功识别验证码!') return result raise Exception('验证码识别失败: ', result)
def _get_verifycode(self, code_string): """ 使用超级鹰识别验证码 :param pcid: :return: """ captcha_url = f'https://passport.baidu.com/cgi-bin/genimage?{code_string}' img_data = self.session.get(captcha_url).content self.logger.info('使用超级鹰识别验证码...') ok, result = image_to_text(img_data) if ok: self.logger.info('成功识别验证码!') return result raise Exception('验证码识别失败: ', result)