feat: parse profile page header
This commit is contained in:
+25
-1
@@ -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 };
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user