【#文档大全网# 导语】以下是®文档大全网的小编为您整理的《基于Python的老黄历网开放接口调用代码实例》,欢迎阅读!
基于Python的老黄历网开放接口调用代码实例
代码描述:基于Python的老黄历网开放接口调用代码实例 代码平台:聚合数据
#!/usr/bin/python
# -*- coding: utf-8 -*- importjson, urllib
fromurllib importurlencode
#---------------------------------- # 老黄历调用示例代码 - 聚合数据
# 在线接口文档:http://www.juhe.cn/docs/65 #----------------------------------
defmain():
#配置您申请的APPKey
appkey ="*********************"
#1.日历
request1(appkey,"GET")
#2.时辰
request2(appkey,"GET")
#日历
defrequest1(appkey, m="GET"):
url ="http://v.juhe.cn/laohuangli/d" params ={
"key": appkey, #应用APPKEY(应用详细页查询) "date": "", #日期,格式2014-09-09
}
params =urlencode(params) ifm =="GET":
f =urllib.urlopen("%s?%s"%(url, params)) else:
f =urllib.urlopen(url, params)
"])
content =f.read()
res =json.loads(content) ifres:
error_code =res["error_code"] iferror_code ==0: #成功请求
printres["result"] else:
print"%s:%s"%(res["error_code"],res["reason
else:
print"request api error"
#时辰
defrequest2(appkey, m="GET"):
url ="http://v.juhe.cn/laohuangli/h" params ={
"key": appkey, #应用APPKEY(应用详细页查询) "date": "", #日期,格式2014-09-09
}
params =urlencode(params) ifm =="GET":
f =urllib.urlopen("%s?%s"%(url, params)) else:
f =urllib.urlopen(url, params)
content =f.read()
res =json.loads(content) ifres:
error_code =res["error_code"] iferror_code ==0: #成功请求
printres["result"] else:
print"%s:%s"%(res["error_code"],res["reason
"])
else:
print"request api error"
if__name__ =='__main__':
main()
本文来源:https://www.wddqxz.cn/5ae86b8f336c1eb91b375d6d.html