1
0
Files
jecnarozvrh/scrape/utils/parseTeachers.js
jzitnik-dev c01a64c5b0
All checks were successful
Remote Deploy / deploy (push) Successful in 4s
fix: Try to fix it
2025-08-31 16:40:58 +02:00

27 lines
731 B
JavaScript

const cheerio = require("cheerio");
const fetch = require("node-fetch");
async function parseTeachers() {
const url = "https://spsejecna.cz/ucitel";
const response = await fetch(url);
const data = await response.text(); // fetch needs .text() to get HTML
const $ = cheerio.load(data);
const map = {};
$("main .contentLeftColumn li, main .contentRightColumn li").each((_, el) => {
const link = $(el).find("a");
const href = link.attr("href"); // e.g. "/ucitel/PA"
const text = link.text().trim(); // e.g. "Ing. Bc. Šárka Páltiková"
if (href) {
const key = href.split("/").pop().toLowerCase(); // get "pa"
map[key] = text;
}
});
return map;
}
module.exports = parseTeachers;