Skip to content

Instantly share code, notes, and snippets.

@dragonman225
Created January 6, 2021 09:14
Show Gist options
  • Save dragonman225/5e68ba3137d44d5179abad1064ccb72b to your computer and use it in GitHub Desktop.
Save dragonman225/5e68ba3137d44d5179abad1064ccb72b to your computer and use it in GitHub Desktop.
Crawl course info from timetable.nctu.edu.tw. Remember to install "superagent" package from npm.
const agent = require("superagent")
var domain = "https://timetable.nctu.edu.tw/";
var searchUrl = "?r=main/get_cos_list";
var academicYear = "109";
var semester = "1";
var courseNumber = "1144";
agent
.post(domain + searchUrl)
.type("form")
.send({ m_acy: academicYear })
.send({ m_sem: semester })
.send({ m_acyend: academicYear })
.send({ m_semend: semester })
.send({ m_degree: "**" })
.send({ m_dep_uid: "**" })
.send({ m_group: "**" })
.send({ m_grade: "**" })
.send({ m_class: "**" })
.send({ m_option: "cos_id" })
.send({ m_crsname: "**" })
.send({ m_teaname: "**" })
.send({ m_cos_id: courseNumber })
.send({ m_cos_code: "**" })
.send({ m_crstime: "**" })
.send({ m_crsoutline: "**" })
.send({ m_costype: "**" })
.end(function (err, res) {
res = JSON.parse(res.text);
try {
var courses = res[Object.keys(res)[0]]["1"];
var course = courses[Object.keys(courses)[0]];
console.log({
number: course["cos_id"],
name: course["cos_cname"],
registered_num: course["reg_num"],
lecturer: course["teacher"]
});
} catch (e) {
console.log({ error: true });
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment