Created
September 11, 2021 07:20
-
-
Save JialuGong/f7f32aef024a6806ee36eb0502500b9d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const superagent = require("superagent"); | |
const fs = require('fs'); | |
const pageUrl = "https://jw.ustc.edu.cn/for-std/course-select/352169/turn/481/select"; | |
const userAgent = "USER_AGENT = 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.159 Safari/537.36'"; | |
const addLessonUrl = 'https://jw.ustc.edu.cn/ws/for-std/course-select/add-request'; | |
const cookiePromise = new Promise((res, rej) => { | |
fs.readFile('./config.json', (err, data) => { | |
if (err) rej(err); | |
else res(data) | |
}) | |
}); | |
const courseId = '137249'; | |
(async () => { | |
try { | |
const cookieRes = await cookiePromise; | |
const cookieJson = JSON.parse(cookieRes); | |
const cookieCotent = `SESSION=${cookieJson.SESSION}; SVRNAME=${cookieJson.SVRNAME}`; | |
console.log(cookieCotent) | |
const res = await superagent.get(pageUrl).set("cookie", cookieCotent).set("User-Agent", userAgent); | |
const studentId = /(?<=studentId: )[0-9]+/.exec(res.text)[0]; | |
const turnId = /(?<=turnId: )[0-9]+/.exec(res.text)[0]; | |
console.log({ turnId, studentId }) | |
const result = await superagent.post(addLessonUrl) | |
.set("cookie", cookieCotent) | |
.set("User-Agent", userAgent) | |
.set('Content-Type', 'multipart/form-data') | |
.field('studentAssoc', studentId) | |
.field('lessonAssoc', courseId) | |
.field('courseSelectTurnAssoc', turnId) | |
.field('scheduleGroupAssoc','') | |
.field('virtualCost', 0); | |
console.log(result) | |
} catch (err) { | |
console.log(err); | |
} | |
} | |
)(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment