基于Python的脑筋急转弯大全及答案api调用代码实例

2022-05-20 02:28:18   第一文档网     [ 字体: ] [ 阅读: ] [ 文档下载 ]
说明:文章内容仅供预览,部分内容可能不全。下载后的文档,内容与下面显示的完全一致。下载之前请确认下面内容是否您想要的,是否完整无缺。下载word有问题请添加QQ:admin处理,感谢您的支持与谅解。点击这里给我发消息

#第一文档网# 导语】以下是®第一文档网的小编为您整理的《基于Python的脑筋急转弯大全及答案api调用代码实例》,欢迎阅读!
急转弯,调用,脑筋,实例,基于

基于Python的脑筋急转弯大全及答案api调用代码实例



代码描述:基于Python的脑筋急转弯大全及答案api调用代码实例 代码平台:聚合数据



#!/usr/bin/python

# -*- coding: utf-8 -*- import json, urllib

from urllib import urlencode



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

# 鬼马问答调用示例代码 聚合数据

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



def main():



#配置您申请的APPKey

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



#1.接口类型查询

request1(appkey,"GET")



#2.接口数据查询

request2(appkey,"GET")



#3.接口答案查询

request3(appkey,"GET")



#接口类型查询

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

url = "http://japi.juhe.cn/askanswer/getTypes" params = {

"key" : appkey, #应用APPKEY



}

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://japi.juhe.cn/askanswer/getCat" params = {

"key" : appkey, #APP Key

"cat" : "", #接口类型序号,默认为1(脑筋急转弯) "start" : "", #起始位置,默认为0 "count" : "", #返回条数,默认为20



}

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 request3(appkey, m="GET"):

url = "http://japi.juhe.cn/askanswer/answer" params = {

"key" : appkey, #APP Key "id" : "", #题目id



}

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()


本文来源:https://www.dywdw.cn/ee58a87ef524ccbff021841c.html

相关推荐
推荐阅读