#本文仅供学习之用 import requests import json import pandas as pd cookies = { 'BAIDU_SSP_lcr': 'https://www.baidu.com/link?url=oajPJpjaszOfB6AIZl7n82yJSTP0lGicM3lfK9k9S5e&wd=&eqid=9cbb9a10006186800000000366a1f022', 'PHPSESSID': 'ucmv2u4jm1jbqki4oh9m238gf2', 'Hm_lvt_12e4883fd1649d006e3ae22a39f97330': '1721888810', 'HMACCOUNT': '70E52AFDD5606235', 'Hm_lvt_692bd5f9c07d3ebd0063062fb0d7622f': '1721888810', '_gid': 'GA1.2.365190144.1721888810', '_gat_UA-66069030-3': '1', 'Hm_lpvt_692bd5f9c07d3ebd0063062fb0d7622f': '1721889271', '_ga_9FDP3NWFMS': 'GS1.1.1721888809.1.1.1721889285.0.0.0', '_ga': 'GA1.2.1637905841.1721888810', 'Hm_lpvt_12e4883fd1649d006e3ae22a39f97330': '1721889285', } headers = { 'Accept': '*/*', 'Accept-Language': 'zh-CN,zh;q=0.9', 'Connection': 'keep-alive', # 'Cookie': 'BAIDU_SSP_lcr=https://www.baidu.com/link?url=oajPJpjaszOfB6AIZl7n82yJSTP0lGicM3lfK9k9S5e&wd=&eqid=9cbb9a10006186800000000366a1f022; PHPSESSID=ucmv2u4jm1jbqki4oh9m238gf2; Hm_lvt_12e4883fd1649d006e3ae22a39f97330=1721888810; HMACCOUNT=70E52AFDD5606235; Hm_lvt_692bd5f9c07d3ebd0063062fb0d7622f=1721888810; _gid=GA1.2.365190144.1721888810; _gat_UA-66069030-3=1; Hm_lpvt_692bd5f9c07d3ebd0063062fb0d7622f=1721889271; _ga_9FDP3NWFMS=GS1.1.1721888809.1.1.1721889285.0.0.0; _ga=GA1.2.1637905841.1721888810; Hm_lpvt_12e4883fd1649d006e3ae22a39f97330=1721889285', 'Referer': 'https://www.zhcw.com/', 'Sec-Fetch-Dest': 'script', 'Sec-Fetch-Mode': 'no-cors', 'Sec-Fetch-Site': 'same-site', 'User-Agent': 'Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Mobile Safari/537.36', 'sec-ch-ua': '"Not/A)Brand";v="8", "Chromium";v="126", "Google Chrome";v="126"', 'sec-ch-ua-mobile': '?1', 'sec-ch-ua-platform': '"Android"', } params = { # 'callback': 'jQuery112207244858761840212_1721889285150', 'transactionType': '10001001', 'lotteryId': '1', 'issueCount': '100', 'startIssue': '', 'endIssue': '', 'startDate': '', 'endDate': '', 'type': '0', 'pageNum': '1', 'pageSize': '100', 'tt': '0.7742030302196585', '_': '1721889285151', } response = requests.get('https://jc.zhcw.com/port/client_json.php', params=params, cookies=cookies, headers=headers) #这里打印输出时是一个函数,如何将函数名取掉,是一个JSON代码 # print(response.text) context = json.loads(response.text) # print(context) #定义一个列表存储需要的数据 lst=[] for i in context['data']: # print(i) #定义一个字典 dic = {} dic['期号']=i['issue'] dic['开奖日期']=i['openTime'] dic['红球']=i['frontWinningNum'] dic['蓝球'] = i['backWinningNum'] dic['开奖红球'] = i['seqFrontWinningNum'] dic['开奖蓝球'] = i['seqBackWinningNum'] #将字黄内容添加到列表 lst.append(dic) df=pd.DataFrame(lst) 将列表内容输出csv文件 # print(df) df.to_csv('./近100期双色球.csv') data = pd.read_csv('./近100期双色球.csv',index_col=1) print(data)