forked from RainySY/chaoxing-xuexitong-autoflush
-
Notifications
You must be signed in to change notification settings - Fork 0
/
courselist.js
40 lines (37 loc) · 1.13 KB
/
courselist.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
var cheerio = require("cheerio");
var url = require("url");
var qs = require("querystring");
class courselist {
constructor(user) {
this.user = user;
}
async getList() {
// let $ = cheerio.load(await this.user.net.get("visit/interaction"));
// 课程查询接口换了
let $ = cheerio.load(
await this.user.net.get("visit/courselistdata", {
// 此处需要参数,否则返回的是自己教的课
courseType: 1,
})
);
// let courses = $(".course");
// console.log($().html());
let courses = $("#courseList").find(".course");
let built = [];
for (let i = 0; i < courses.length; i++) {
let course = courses.eq(i).find("a");
let t_url = course.attr("href");
if (typeof t_url !== "string") {
continue;
}
let target = url.parse(t_url);
let query = qs.parse(target.query);
// let title = course.attr("title");
// 寻找子元素就好了
let title = course.find("span").attr("title");
built.push({ courseId: query.courseid, clazzId: query.clazzid, title });
}
return built;
}
}
module.exports = courselist;