@makepad/school-names-turkey
Version:
A npm module that scrapes all the school names from turkish education ministry's page
53 lines (52 loc) • 2.39 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const puppeteer_1 = __importDefault(require("puppeteer"));
class SchoolNameListScraper {
async init(headless = true, args = [
'--no-sandbox',
'--disable-setuid-sendbox',
'--disable-dev-shm-usage',
'--disable-accelerated-2d-canvas',
'--disable-gpu',
]) {
this.config = {
headless,
args,
};
if (process.arch === 'arm' || process.arch === 'arm64') {
this.config.executablePath = 'chromium-browser';
}
this.browser = await puppeteer_1.default.launch(this.config);
this.page = await this.browser.newPage();
}
async getSchoolList(city) {
var _a, _b, _c, _d, _e, _f;
await ((_a = this.page) === null || _a === void 0 ? void 0 : _a.goto(`http://www.meb.gov.tr/baglantilar/okullar/index.php?ILKODU=${city.code}`, { timeout: 500000 }));
const listSelector = '//table[@id="icerik-listesi"]/tbody/tr';
await ((_b = this.page) === null || _b === void 0 ? void 0 : _b.waitForXPath(listSelector));
const s = await ((_c = this.page) === null || _c === void 0 ? void 0 : _c.$x(listSelector));
const result = [];
for (let i = 0; i < (s ? s === null || s === void 0 ? void 0 : s.length : 0); i += 1) {
const schoolNameSelector = `${listSelector}[${i + 1}]/td[1]/a`;
const sne = (await ((_d = this.page) === null || _d === void 0 ? void 0 : _d.$x(schoolNameSelector)))[0];
const sn = await ((_e = this.page) === null || _e === void 0 ? void 0 : _e.evaluate((e) => e.innerText, sne));
const sl = await ((_f = this.page) === null || _f === void 0 ? void 0 : _f.evaluate((e) => e.getAttribute('href'), sne));
const t = sn.split(' - ');
result.push({
cityName: t[0].trim(),
provinceName: t[1].trim(),
schoolName: t[2].trim(),
url: sl.trim(),
});
}
return result;
}
async close() {
var _a;
await ((_a = this.browser) === null || _a === void 0 ? void 0 : _a.close());
}
}
exports.default = SchoolNameListScraper;