1 Star 0 Fork 0

大学失业人员/leetcode爬虫

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
pta_function.py 2.08 KB
一键复制 编辑 原始数据 按行查看 历史
大学失业人员 提交于 2023-04-03 14:41 . 添加代码
# _*_ 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')
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/Oliveira123/Users_data_spider.git
[email protected]:Oliveira123/Users_data_spider.git
Oliveira123
Users_data_spider
leetcode爬虫
master

搜索帮助