@makepad/school-names-turkey
Version:
A npm module that scrapes all the school names from turkish education ministry's page
43 lines (42 loc) • 2.24 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 Browser {
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, _g;
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));
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 schoolDetailsPageSelector = `${listSelector}[${i + 1}]/td[2]/a`;
const sne = (await ((_d = this.page) === null || _d === void 0 ? void 0 : _d.$x(schoolNameSelector)))[0];
const deps = (await ((_e = this.page) === null || _e === void 0 ? void 0 : _e.$x(schoolDetailsPageSelector)))[0];
const sn = await ((_f = this.page) === null || _f === void 0 ? void 0 : _f.evaluate((e) => e.innerText, sne));
const sdp = await ((_g = this.page) === null || _g === void 0 ? void 0 : _g.evaluate((e) => e.getAttribute('href'), deps));
console.log(`School name: ${sn}\t School details page: ${sdp}`);
}
}
}
exports.default = Browser;