代码拉取完成,页面将自动刷新
# _*_ coding: utf-8 _*_
"""
Time: 2023/1/8 15:15
Author: Yi Zhan
Version: V 0.1
File: pta_function.py
"""
import urllib
import json
import requests
import xlwt
url = "https://pintia.cn/api/problem-sets/13/problem-list?exam_id=1174864404891553792&problem_type=CODE_COMPLETION&limit=100"
headers = {
"Accept": "application/json;charset=UTF-8",
"Content-Type": "application/json;charset=UTF-8",
"Cookie": "_ga=GA1.2.493884443.1672939442; __gads=ID=2d7a655dc76fc2f8-229f611f2dd900b5:T=1672939442:RT=1672939442:S=ALNI_MbraEWwhp2m44DBcaTzpqGyIc191w; PTASession=075dd9ef-f38c-4b00-bf41-387d3c0fd77c; __gpi=UID=00000b9ea9759460:T=1672939442:RT=1673357711:S=ALNI_Mbwpu08LbhqthkE7EEHgDsAr2Qx1w; JSESSIONID=A50DCF24900657560C0C57BAB3CD2A69",
"Referer": "https://pintia.cn/problem-sets/13/exam/problems/type/7?page=0",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36"
}
request = urllib.request.Request(url=url , headers=headers)
response = urllib.request.urlopen(request)
content = response.read().decode('utf-8')
print(content)
data = json.loads(content)
print(data)
# 创建一个workbook 设置编码
workbook = xlwt.Workbook(encoding = 'utf-8')
# 创建一个worksheet
worksheet = workbook.add_sheet('My Worksheet')
worksheet.write(0, 0, label = 'id')
worksheet.write(0, 1, label = 'label')
worksheet.write(0, 2, label = 'score')
worksheet.write(0, 3, label = 'deadline')
worksheet.write(0, 4, label = 'acceptCount')
worksheet.write(0, 5, label = 'submitCount')
worksheet.write(0, 6, label = 'title')
leng = data['problemSetProblems']
for i in range(len(leng)):
worksheet.write(i + 1, 0, label=leng[i]['id'])
worksheet.write(i + 1, 1, label=leng[i]['label'])
worksheet.write(i + 1, 2, label=leng[i]['score'])
worksheet.write(i + 1, 3, label=leng[i]['deadline'])
worksheet.write(i + 1, 4, label=leng[i]['acceptCount'])
worksheet.write(i + 1, 5, label=leng[i]['submitCount'])
worksheet.write(i + 1, 6, label=leng[i]['title'])
workbook.save('pta_function.xls')
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。