基于Python的健康知识api调用代码实例.docVIP

  • 2
  • 0
  • 约3.14千字
  • 约 4页
  • 2017-06-12 发布于北京
  • 举报

基于Python的健康知识api调用代码实例.doc

基于Python的健康知识api调用代码实例 代码描述:基于Python的健康知识api调用代码实例 代码平台:聚合数据 #!/usr/bin/python # -*- coding: utf-8 -*- import json, urllib from urllib import urlencode ? # # 健康知识调用示例代码 - 聚合数据 # 在线接口文档:/docs/143 # ? def main(): ? ????#配置您申请的APPKey ????appkey = ********************* ? ????#1.最新健康知识列表 ????request1(appkey,GET) ? ????#2.健康知识分类列表 ????request2(appkey,GET) ? ????#3.健康知识信息列表 ????request3(appkey,GET) ? ????#4.健康知识详细信息 ????request4(appkey,GET) ? ? ? #最新健康知识列表 def request1(appkey, m=GET): ????url = /health_knowledge/infoNews ????params = { ????????key : appkey, #应用APPKEY ????????id : , #当前最新的知识的id ????????rows : , #返回最新关键词的条数,默认rows=20 ????????classify : , #分类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 ? #健康知识分类列表 def request2(appkey, m=GET): ????url = /health_knowledge/categoryList ????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 request3(appkey, m=GET): ????url = /health_knowledge/infoList ????params = { ????????key : appkey, #应用APPKEY ????????page : , #请求页数,默认是1 ????????limit : , #每页返回的条数,默认是20 ????????id : , #这里是指知识分类的ID 默认为 null ,也就是全部。 ? ????} ????params = urlencode(params) ????if m ==GET: ????????f = urllib.

文档评论(0)

1亿VIP精品文档

相关文档