import json import pandas as pd import requests data1 = pd.read_excel('C:\\Users\\Administrator\\PycharmProjects\\pythonProject10\\用户信息.xls') head = { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:92.0) Gecko/20100101 Firefox/92.0', 'cookie': 'UM_distinctid=17fed3bf7296d4-01aeae5d80942c-1f343371-1fa400-17fed3bf72a1163; __client_id=2ec00f15870204623a78bf6f63f7c99a85774791; CNZZDATA5476811=cnzz_eid%3D1690978113-1633007100-https%253A\%252F\%252Fcn.bing.com\%252F%26ntime%3D1651749421; _uid=0; login_referer=https%3A\%2F\%2Fwww.luogu.com.cn\%2Fuser\%2F387021' } data = requests.get("https://www.luogu.com.cn/fe/api/contest/scoreboard/68651?page=1", headers=head) data.encoding = 'utf-8' json_object = json.loads(data.text) g = dict() rank = dict() ID = {'U197159': 'A', 'U196210': 'B', 'U215461': 'C', 'U197241': 'D', 'U197281': 'E', 'U215474': 'F', 'U197124': 'G', 'U215470': 'H'} idx = 1 for i in json_object['scoreboard']['result']: g[i['user']['name']] = [] rank[i['user']['name']] = idx idx = idx + 1 for j in i['details']: if i['details'][j]['score'] >= 0: g[i['user']['name']].append(ID[j]) for i in range(33): if data1.loc[i, '洛谷账号'] in rank.keys(): data1.loc[i, '排名'] = rank[data1.loc[i, '洛谷账号']] for j in g[data1.loc[i, '洛谷账号']]: data1.loc[i, j] = 'AC' else: data1.loc[i, '排名'] = -1 data1.to_excel('C:\\Users\\Administrator\\PycharmProjects\\pythonProject10\\result.xls', index=False)
时间: 2023-09-24 12:11:15 浏览: 51
这段代码是用来爬取洛谷比赛成绩并将其和本地 Excel 文件中的用户信息进行匹配,最后将结果输出到本地 Excel 文件。但是在代码中出现了一个错误,导致代码无法正常运行。
错误可能是由于代码中引用的文件路径不正确或者 Excel 文件格式不受 Pandas 支持所致。您可以检查一下文件路径是否正确,并尝试使用 Pandas 支持的其他文件格式(如 CSV)来解决这个问题。另外,您也可以查看代码中是否存在其他语法错误或逻辑错误。