UNPKG

source-scraper-core

Version:
24 lines (23 loc) 1.14 kB
import { Configurable, IConfigurable, IOptions } from './Configurable'; import { IScrap, Scrap } from './Scrap'; export interface IScraperData { name: string; domains: string[]; urlPattern: RegExp; } export declare type IScraperOptions = IOptions; export interface IScraper<T, SO extends IScraperOptions = IScraperOptions> extends IScraperData, IConfigurable<SO> { scrap: (url: string, options?: SO) => Promise<IScrap<T>>; } export declare abstract class Scraper<T, SO extends IScraperOptions = IScraperOptions> extends Configurable<SO> implements IScraper<T, SO> { abstract name: string; abstract domains: string[]; abstract urlPattern: RegExp; isApplicable(url: string): boolean; isApplicableDomain(domain: string): boolean; getUrlData(url: string, throwIfNull: true): RegExpExecArray; getUrlData(url: string, throwIfNull: false): RegExpExecArray | null; scrap(url: string, options?: SO): Promise<Scrap<T>>; protected getScrap(url: string, dataSupplier: () => Promise<T>): Promise<Scrap<T>>; protected abstract exec(url: string, options: SO): Promise<T>; }