eoLinker-API_Shop_水族宠物大全_API接口_Python调用示例代码
eoLinker-API Shop 水族水族宠宠物大全物大全 Python调调用示例代用示例代码码水族水族宠宠物大全物大全获取水族宠物的相关信息,包括品种介绍、产地、性格、寿命、常见疾病等信息, 带图片。该产该产品品拥拥有以下有以下APIs: :1.获取水族宠物列表2.关键字获取水族列表3.获取水族动物信息注意,注意,该该示例代示例代码仅码仅适用于适用于 www.apishop.net 网站下网站下API 使用使用该产该产品前,您需要通品前,您需要通过过 https:/www.apishop.net/#/api/detail/?productID=200 申申请请API服服务务1.获获取水族取水族宠宠物列表物列表 #!/usr/bin/env python # -*- coding: utf-8 -*- # 测试环境: python2.7 # 安装requests依赖 => pip install requests/ easy_install requests# 导入requests依赖 import requests import json import sysreload(sys) sys.setdefaultencoding('utf-8')def apishop_send_request(method, url, params=None, headers=None):'''转发请求到目的主机param method str 请求方法param url str 请求地址param params dict 请求参数param headers dict 请求头'''method = str.upper(method)if method = 'POST':return requests.post(url=url, data=params, headers=headers)elif method = 'GET':return requests.get(url=url, params=params, headers=headers)else:return Nonemethod = “POST“ url = “https:/api.apishop.net/common/aquariumFamily/queryAquariumList“ headers = None params = “apiKey“:“your_api_key“, #需要从www.apishop.net获取 “page“:“ #当前页码 “pageSize“:“ #当前页面水族宠物数量 result = apishop_send_request(method=method, url=url, params=params, headers=headers) if result:body = result.textresponse = json.loads(body)status_code = response“statusCode“if (status_code = '000000'):# 状态码为000000, 说明请求成功print('请求成功:%s' % (body,)else:# 状态码非000000, 说明请求失败print('请求失败: %s' % (body,) else:# 返回内容异常,发送请求失败print('发送请求失败')2.关关键键字字获获取水族列表取水族列表 #!/usr/bin/env python # -*- coding: utf-8 -*- # 测试环境: python2.7 # 安装requests依赖 => pip install requests/ easy_install requests# 导入requests依赖 import requests import json import sysreload(sys) sys.setdefaultencoding('utf-8')def apishop_send_request(method, url, params=None, headers=None):'''转发请求到目的主机param method str 请求方法param url str 请求地址param params dict 请求参数param headers dict 请求头'''method = str.upper(method)if method = 'POST':return requests.post(url=url, data=params, headers=headers)elif method = 'GET':return requests.get(url=url, params=params, headers=headers)else:return Nonemethod = “POST“ url = “https:/api.apishop.net/common/aquariumFamily/queryAquariumListByKeywo rd“ headers = None params = “apiKey“:“your_api_key“, #需要从www.apishop.net获取 “page“:“ #当前页码 “pageSize“:“ #当前页面水族宠物数量 “keyword“:“ #关键字 result = apishop_send_request(method=method, url=url, params=params, headers=headers) if result:body = result.textresponse = json.loads(body)status_code = response“statusCode“if (status_code = '000000'):# 状态码为000000, 说明请求成功print('请求成功:%s' % (body,)else:# 状态码非000000, 说明请求失败print('请求失败: %s' % (body,) else:# 返回内容异常,发送请求失败print('发送请求失败')3.获获取水族取水族动动物信息物信息 #!/usr/bin/env python # -*- coding: utf-8 -*- # 测试环境: python2.7 # 安装requests依赖 => pip install requests/ easy_install requests# 导入requests依赖 import requests import json import sysreload(sys) sys.setdefaultencoding('utf-8')def apishop_send_request(method, url, params=None, headers=None):'''转发请求到目的主机param method str 请求方法param url str 请求地址param params dict 请求参数param headers dict 请求头'''method = str.upper(method)if method = 'POST':return requests.post(url=url, data=params, headers=headers)elif method = 'GET':return requests.get(url=url, params=params, headers=headers)else:return Nonemethod = “POST“ url = “https:/api.apishop.net/common/aquariumFamily/queryAquariumInfo“ headers = None params = “apiKey“:“your_api_key“, #需要从www.apishop.net获取 “petID“:“ #宠物ID result = apishop_send_request(method=method, url=url, params=params, headers=headers) if result:body = result.textresponse = json.loads(body)status_code = response“statusCode“if (status_code = '000000'):# 状态码为000000, 说明请求成功print('请求成功:%s' % (body,)else:# 状态码非000000, 说明请求失败print('请求失败: %s' % (body,) else:# 返回内容异常,发送请求失败print('发送请求失败')