feat: parse profile page header

This commit is contained in:
2026-08-18 15:28:12 +08:00
parent 06d9a4be11
commit 3c409ea048
2 changed files with 36 additions and 1 deletions
+25 -1
View File
@@ -46,5 +46,29 @@
}));
}
return { parseStudyLoadTable };
function parseProfilePage(html) {
const result = {};
const bMatch = /<b>([\s\S]*?)<\/b>/i.exec(html);
if (bMatch) result.program = cleanText(bMatch[1]);
const smallMatch = /<small>([\s\S]*?)<\/small>/i.exec(html);
if (smallMatch) {
const lines = smallMatch[1].split(/<br\s*\/?>/i).map(cleanText).filter(Boolean);
result.semester = lines[lines.length - 1] || '';
}
const kvRe = /<td[^>]*>([\s\S]*?)<\/td>\s*<td[^>]*class="bold"[^>]*>([\s\S]*?)<\/td>/gi;
let m;
while ((m = kvRe.exec(html)) !== null) {
const key = cleanText(m[1]);
const val = cleanText(m[2]);
if (/full name/i.test(key)) result.fullName = val;
else if (/student id/i.test(key)) result.studentId = val;
else if (/year level/i.test(key)) result.yearLevel = val;
else if (/student type/i.test(key)) result.studentType = val;
}
return result;
}
return { parseStudyLoadTable, parseProfilePage };
});