60 lines
1.9 KiB
Python
Executable File
60 lines
1.9 KiB
Python
Executable File
# 爬取学升中的课程目录
|
|
|
|
import json
|
|
import os
|
|
import random
|
|
import time
|
|
|
|
import requests
|
|
|
|
# 使用BearerToken认证
|
|
BearerToken = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiIxMDAwMDgzNDciLCJleHAiOjE2OTMwNjMxNTEsImp0aSI6ImUxMGYxMDEyLTY3MDYtNGJiYS1iMTg2LWVmNGViZmVhZDVkMCIsImlhdCI6MTY5MDM4NDc1MSwiaXNzIjoiYXBwdXNlciIsInVpZCI6ImJlMmViOGIyLTFhOTItNGVmMC05ZDAwLTA1YTlkN2E2OWRiMiIsInNjaGVtZSI6Imp3dGhzIiwic2lkIjoiMWI4ZjE1ZTItYjQ5ZC00MmRmLWEwNDUtZmQxYTUwNzI5ZjkxIn0.9TAgxEBSg_Ckbyif8IsC18MMqb9I2qhSwcPbNFk7JhE'
|
|
|
|
# 请求头
|
|
headers = {
|
|
'authority': 'bandu-api.songy.info',
|
|
'accept': '*/*',
|
|
'accept-language': 'zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6',
|
|
'authorization': 'Bearer ' + BearerToken,
|
|
'dnt': '1',
|
|
'origin': 'https://webapp.songy.info',
|
|
'referer': 'https://webapp.songy.info/',
|
|
'sec-ch-ua': '"Not/A)Brand";v="99", "Microsoft Edge";v="115", "Chromium";v="115"',
|
|
'sec-ch-ua-mobile': '?0',
|
|
'sec-ch-ua-platform': '"Windows"',
|
|
'sec-fetch-dest': 'empty',
|
|
'sec-fetch-mode': 'cors',
|
|
'sec-fetch-site': 'same-site',
|
|
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36 Edg/115.0.1901.188',
|
|
}
|
|
|
|
# 请求参数
|
|
params = {
|
|
'q': '',
|
|
'offset': '0',
|
|
'limit': '20',
|
|
# 'sort': 'oldest-first',
|
|
}
|
|
|
|
has_more = True
|
|
offset = 0
|
|
# data_item = []
|
|
|
|
while(has_more):
|
|
|
|
time.sleep(1 + random.uniform(0.1, 1.2))
|
|
response = requests.get('https://bandu-api.songy.info/v1/communities/80000002/courses', params=params, headers=headers)
|
|
data = json.loads(response.text);
|
|
# data_item += data['data']['items']
|
|
has_more = data['data']['has_more']
|
|
offset += 20
|
|
print(offset)
|
|
params['offset'] = str(offset)
|
|
with open(os.path.join('courses.json'), 'a') as file:
|
|
file.write(response.text)
|
|
# if offset == 40:
|
|
# break
|
|
|
|
|
|
|