基于Python的中国彩票开奖结果接口调用代码实例

时间:2022-07-11 21:14:15 阅读: 最新文章 文档下载
说明:文章内容仅供预览,部分内容可能不全。下载后的文档,内容与下面显示的完全一致。下载之前请确认下面内容是否您想要的,是否完整无缺。
基于Python的中国彩票开奖结果接口调用代码实例

代码描述:基于Python的中国彩票开奖结果接口调用代码实例 代码平台:聚合数据



#!/usr/bin/python

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

from urllib import urlencode



#---------------------------------- # 中国彩票开奖结果调用示例代码 聚合数据 # 在线接口文档:http://www.juhe.cn/docs/53 #----------------------------------



def main():



#配置您申请的APPKey

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



#1.彩票开奖结果查询

request1(appkey,"GET")



#2.历史开奖数据查询

request2(appkey,"GET")



#3.支持彩种列表

request3(appkey,"GET")



#彩票开奖结果查询

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

url = "http://v.juhe.cn/lottery/query" params = {

"key" : appkey, #应用APPKEY(应用详细页查询) "lotteryid" : "", #彩票ID

"date" : "", #指定开奖日期2014-08-01,不指定默返回最近开奖结果 "dtype" : "", #返回数据的格式,xmljson,默认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://v.juhe.cn/lottery/history" params = {

"key" : appkey, #应用APPKEY(应用详细页查询) "lotteryid" : "", #彩票ID

"year" : "", #指定年份,如2013,默认2014

"dtype" : "", #返回数据的格式,xmljson,默认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 request3(appkey, m="GET"):

url = "http://v.juhe.cn/lottery/lolist" params = {

"key" : appkey, #应用APPKEY(应用详细页查询)

"dtype" : "", #返回数据的格式,xmljson,默认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()


本文来源:https://www.wddqw.com/doc/469435ee915f804d2a16c118.html