UNPKG

1.12 kBTypeScriptView Raw
1/// <reference types="cheerio" />
2
3declare namespace scrapeIt {
4 export interface ScrapeOptions {
5 [key: string]: string | ScrapeOptionList | ScrapeOptionElement;
6 }
7
8 export interface ScrapeOptionElement {
9 selector?: string;
10 convert?: (value: any) => any;
11 how?: string | ((element: CheerioSelector) => any);
12 attr?: string;
13 trim?: boolean;
14 closest?: string;
15 eq?: number;
16 texteq?: number;
17 }
18
19 export interface ScrapeOptionList {
20 listItem: string;
21 data?: ScrapeOptions;
22 convert?: (value: any) => any;
23 }
24
25 export interface ScrapeResult<T> {
26 data: T,
27 $: Cheerio,
28 response: any,
29 body: string
30 }
31
32 export function scrapeHTML<T>(body: CheerioStatic | string, options: ScrapeOptions): T;
33}
34
35declare function scrapeIt<T>(url: string | object, opts: scrapeIt.ScrapeOptions): Promise<scrapeIt.ScrapeResult<T>>;
36
37declare function scrapeIt<T>(url: string | object, opts: scrapeIt.ScrapeOptions, cb: (err: any, res: scrapeIt.ScrapeResult<T>) => void): void;
38export = scrapeIt;