萌新刚学 python,爬虫 CE 求助
  • 板块学术版
  • 楼主昒昕
  • 当前回复11
  • 已保存回复11
  • 发布时间2022/6/13 19:44
  • 上次更新2023/10/27 23:21:53
查看原帖
萌新刚学 python,爬虫 CE 求助
84132
昒昕楼主2022/6/13 19:44

如题,完整代码如下。

代码作用为爬取洛谷某一用户的练习情况(即 AC 了哪些题,可以用于绑定洛谷账号&同步练习情况)

import requests
import os
#uid=int(input())
uid=int(84132)
url='https://www.luogu.com.cn/user/'+str(uid)+'?_contentOnly'
head={"User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.130 Safari/537.36"}
response = requests.get(url=url,headers=head)
#out=str(response.text).encode('utf-8').decode('unicode_escape')
res=response.json()
#print(res['currentData']['user']['name'])
user=res['currentData']['user']
passed=res['currentData']['passedProblems']
submitted=res['currentData']['submittedProblems']

class stats:
    uid=uid
    name=user['name']
    color=user['color']
    ccflevel=user['ccfLevel']
    tag=user['badge']
    passed_num=user['passedProblemCount']
    submitted_num=user['submittedProblemCount']
    unpassed_num=len(submitted)
    hideinfo=False
if passed:
    stats.hideinfo=True

if not os.path.exists(str(uid)):
        os.makedirs(str(uid))
f=open(str(uid)+'/practice.txt','w')

#for i in range(len(passed)):
#    f.write(str('['+str(passed[i]['pid']+' '+passed[i]['title']+']'))

#f.write('[',passed[i]['pid'],' ',passed[i]['title'],'\n')

for i in range(len(passed)):
    f.write('[',str(passed[i]['pid'],' ',passed[i]['title'],']')

f.write('[',str(passed[i]['pid'],' ',passed[i]['title'],']') 出现错误,报错原因是

unexpected EOF while parsing

求告知 CE 原因,谢谢。

这意叉洛谷什么【】判定啊,有 badge 关键字不能发,关掉才能发

2022/6/13 19:44
加载中...