UNPKG

source-scraper-core

Version:
41 lines 1.25 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const Configurable_1 = require("./Configurable"); const Scrap_1 = require("./Scrap"); class Scraper extends Configurable_1.Configurable { isApplicable(url) { return this.urlPattern.test(url); } isApplicableDomain(domain) { return this.domains.some(d => d === domain); } getUrlData(url, throwIfNull = false) { const data = this.urlPattern.exec(url); if (throwIfNull && !Array.isArray(data)) throw new Error('Unexpected url format'); return data; } async scrap(url, options) { return this.getScrap(url, async () => this.exec(url, this.getOptions(options))); } async getScrap(url, dataSupplier) { const base = { url, scraper: this }; try { return Scrap_1.Scrap.success({ ...base, data: await dataSupplier() }); } catch (error) { return Scrap_1.Scrap.failure({ ...base, error }); } } } exports.Scraper = Scraper; //# sourceMappingURL=Scraper.js.map