您好,欢迎来到爱go旅游网。
搜索
您的当前位置:首页基于Python的验证码识别接口调用代码实例

基于Python的验证码识别接口调用代码实例

来源:爱go旅游网
基于Python的验证码识别接口调用代码实例

代码描述:基于Python的验证码识别接口调用代码实例

代码平台:聚合数据

#!/usr/bin/python

# -*- coding: utf-8 -*-

import json, urllib

from urllib import urlencode

#----------------------------------

# 验证码识别调用示例代码 - 聚合数据

# 在线接口文档:http://www.juhe.cn/docs/60

#----------------------------------

def main():

#配置您申请的APPKey

appkey = \"*********************\"

#1.识别验证码

request1(appkey,\"POST\")

#2.查询验证码类型代码

request2(appkey,\"GET\")

#识别验证码

def request1(appkey, m=\"GET\"):

url = \"http://op.juhe.cn/vercode/index\"

params = {

\"key\" : appkey, #您申请到的APPKEY

\"codeType\" : \"\#验证码的类型,<a href="http://www.juhe.cn/docs/api/id/60/aid/352" target="_blank">查询</a>

\"image\" : \"\#图片文件

\"dtype\" : \"\#返回的数据的格式,json或xml,默认为json

}

params = urlencode(params)

if m ==\"GET\":

f = urllib.urlopen(\"%s?%s\" % (url, params))

else:

f = urllib.urlopen(url, params)

content = f.read()

res = json.loads(content)

if res:

error_code = res[\"error_code\"]

if error_code == 0:

#成功请求

print res[\"result\"]

else:

print \"%s:%s\" % (res[\"error_code\"],res[\"reason\"])

else:

print \"request api error\"

#查询验证码类型代码

def request2(appkey, m=\"GET\"):

url = \"http://op.juhe.cn/vercode/codeType\"

params = {

\"key\" : appkey, #您申请到的APPKEY

\"dtype\" : \"\#返回的数据的格式,json或xml,默认为json

}

params = urlencode(params)

if m ==\"GET\":

f = urllib.urlopen(\"%s?%s\" % (url, params))

else:

f = urllib.urlopen(url, params)

content = f.read()

res = json.loads(content)

if res:

error_code = res[\"error_code\"]

if error_code == 0:

#成功请求

print res[\"result\"]

else:

print \"%s:%s\" % (res[\"error_code\"],res[\"reason\"])

else:

print \"request api error\"

if __name__ == '__main__':

main()

因篇幅问题不能全部显示,请点此查看更多更全内容

Copyright © 2019- igat.cn 版权所有

违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务