@makepad/school-names-turkey
Version:
A npm module that scrapes all the school names from turkish education ministry's page
41 lines (40 loc) • 1.98 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 SchoolDetailsScraper {
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 getSchoolDetails(url) {
var _a, _b, _c, _d, _e, _f;
await ((_a = this.page) === null || _a === void 0 ? void 0 : _a.goto(url, { 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 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));
console.log(`School name: ${sn}\t School details page: ${sl}`);
}
}
}
exports.default = SchoolDetailsScraper;