闲着无聊,利用python做了一个从官网获取双色球开奖数据的代码,分享给大家:
url = "http://www.cwl.gov.cn/cwl_admin/front/cwlkj/search/kjxx/findDrawNotice?name=ssq&issueCount=&issueStart" \
"=&issueEnd=&dayStart=&dayEnd=&pageNo=2&pageSize=30&week=&systemType=PC "
Accept = "application/json, text/javascript, */*; q=0.01"
Accept_Language = "en-US,en;q=0.9"
Connection = "keep-alive"
Cookie = "HMF_CI" \
"=589e3e39b4c83a8ba2b61ed0c1367d24e22cc89dc9b2500964f868bd36c23e641fbfc84dc6340e4d90ec9bafdd6a351e3582b5efaddd1e4263f570e38c3ce2b401; 21_vq=3 "
Host = "www.cwl.gov.cn"
Referer = "http://www.cwl.gov.cn/ygkj/wqkjgg/ssq/"
X_Request_with = "XMLHttpRequest"
ua = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.135 " \
"Safari/537.36 Edge/12.10240 "
with requests.request('GET', url, headers={"Accept": Accept,
'Accept-Language': Accept_Language,
'Connection': Connection,
'Cookie': Cookie,
'Host': Host,
'Referer': Referer,
'User-agent': ua}) as res:
content = res.text # 获取HTML的内容
# html = etree.HTML(content) # 分析HTML,返回DOM根节点
obj = json.loads(content)
# print(type(obj['result']))
kjList = [] #将结果存在数据中,
for item in obj['result']:
ssq = Ssq(item['code'], item['red'], item['blue']) #从这三个字段时里分取出开奖期数code ,红球代码 red,蓝球代码blue.
kjList.append(ssq)
print(len(kjList))
fmtList = []
kjList.reverse() #获取的数据最新一期在数组0的位置上,为了便于分析可以进行整个数组倒序。
有问题或需要的朋友可以私信我或留言,有时间我会尽量回复大家的。