-
Notifications
You must be signed in to change notification settings - Fork 15
/
scraper.js
executable file
·64 lines (55 loc) · 1.79 KB
/
scraper.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
const tables = document.querySelectorAll(".menu-tbl");
const data = {};
tables.forEach((table, i) => {
const qnType = table.querySelectorAll("tr td.bold")[0].innerText.trim(); // "MCQ || "SA"
const qnID = table.querySelectorAll("tr td.bold")[1].innerText.trim();
if (qnType === "MCQ") {
let hasAnswered = false;
const status2 = table
.querySelectorAll("tr td.bold")[7]
.innerText.trim();
if (status2 !== "--") {
hasAnswered = true;
}
if (hasAnswered) {
let options = [0, 0, 0, 0];
for (let j = 0; j < 4; j++) {
options[j] = Number(
table.querySelectorAll("tr td.bold")[2 + j].innerText
);
}
const ownAnswerIndex =
Number(
table.querySelectorAll("tr td.bold")[7].innerText.trim()
) - 1;
const ownAnswer = options[ownAnswerIndex];
data[qnID] = {
qnType,
hasAnswered,
options,
ownAnswer,
};
} else {
data[qnID] = { qnType, hasAnswered };
}
} else if (qnType === "SA") {
let hasAnswered = false;
const ownAnswer = document
.querySelectorAll(".questionRowTbl")
[i].querySelector("tr:nth-of-type(5) td.bold").innerText;
if (ownAnswer !== "--") {
hasAnswered = true;
}
if (hasAnswered) {
data[qnID] = {
qnType,
hasAnswered,
ownAnswer,
};
} else {
data[qnID] = { qnType, hasAnswered };
}
}
});
const generatedJSON = JSON.stringify(data, null, 2);
console.log(generatedJSON);