@@ -16,17 +16,24 @@ declare interface RunnerArgs<RunnerScrapper> {
1616 scrapper : RunnerScrapper ;
1717 options ?: any ;
1818}
19- export type PuppeteerRunnerScrapper =
20- ( args : { url : string , browser : Browser , page : Page , scrapper : PuppeteerRunnerScrapper , runners : RunnerList } ) => any ;
21- const puppeteerRunner = new Runner ( 'puppeteer' , async ( { url, scrapper, options= { } } : RunnerArgs < PuppeteerRunnerScrapper > ) => {
19+
20+ export type PuppeteerRunnerScrapper = ( args : {
21+ url : string ,
22+ browser : Browser ,
23+ page : Page ,
24+ scrapper : PuppeteerRunnerScrapper ,
25+ runners : RunnerList
26+ } ) => any ;
27+ const puppeteerRunner = new Runner ( 'puppeteer' ,
28+ async ( { url, scrapper, options= { } } : RunnerArgs < PuppeteerRunnerScrapper > ) => {
2229 let _options : any = {
2330 config : {
2431 headless : false
2532 } ,
2633 requestInterception : {
2734 active : true ,
28- block : ( { request } :
29- { request : any , resourceType : string , url : string , page : any , browser : any } ) => request . resourceType === 'font'
35+ block : ( { request } : { request : any , resourceType : string , url : string , page : any , browser : any } ) =>
36+ request . resourceType === 'font'
3037 } ,
3138 init : null
3239 } ;
@@ -42,13 +49,16 @@ const puppeteerRunner = new Runner('puppeteer', async ({url, scrapper, options=
4249
4350 await page . setRequestInterception ( _options . requestInterception && _options . requestInterception . active ) ;
4451 page . on ( 'request' , ( request : any ) => {
45- const block = _options . requestInterception && _options . requestInterception . block && _options . requestInterception . block ( {
46- request,
47- resourceType : request . resourceType ( ) ,
48- url : request . url ( ) ,
49- page,
50- browser
51- } ) ;
52+ const block =
53+ _options . requestInterception &&
54+ _options . requestInterception . block &&
55+ _options . requestInterception . block ( {
56+ request,
57+ resourceType : request . resourceType ( ) ,
58+ url : request . url ( ) ,
59+ page,
60+ browser
61+ } ) ;
5262
5363 if ( typeof block === 'undefined' ) {
5464 return ;
@@ -86,9 +96,15 @@ const puppeteerRunner = new Runner('puppeteer', async ({url, scrapper, options=
8696 await browser . close ( ) ;
8797 }
8898} ) ;
89- export type HTMLRunnerScrapper =
90- ( args : { url : string , html : string , response : any , scrapper : HTMLRunnerScrapper , runners : RunnerList } ) => any ;
91- const htmlRunner = new Runner ( 'html' , async ( { url, scrapper, options= { } } : RunnerArgs < HTMLRunnerScrapper > ) => {
99+ export type HTMLRunnerScrapper = ( args : {
100+ url : string ,
101+ html : string ,
102+ response : any ,
103+ scrapper : HTMLRunnerScrapper ,
104+ runners : RunnerList
105+ } ) => any ;
106+ const htmlRunner = new Runner ( 'html' ,
107+ async ( { url, scrapper, options= { } } : RunnerArgs < HTMLRunnerScrapper > ) => {
92108 let _options : any = {
93109 config : { url,
94110 method : 'get' ,
@@ -111,9 +127,17 @@ const htmlRunner = new Runner('html', async ({url, scrapper, options= {}}: Runne
111127 runners
112128 } ) ;
113129} ) ;
114- export type DOMRunnerScrapper =
115- ( args : { url : string , dom : any , parser : any , html : string , response : any , scrapper : DOMRunnerScrapper , runners : RunnerList } ) => any ;
116- const domRunner = new Runner ( 'dom' , async ( { url, scrapper, options= { } } : RunnerArgs < DOMRunnerScrapper > ) => {
130+ export type DOMRunnerScrapper = ( args : {
131+ url : string ,
132+ dom : any ,
133+ parser : any ,
134+ html : string ,
135+ response : any ,
136+ scrapper : DOMRunnerScrapper ,
137+ runners : RunnerList
138+ } ) => any ;
139+ const domRunner = new Runner ( 'dom' ,
140+ async ( { url, scrapper, options= { } } : RunnerArgs < DOMRunnerScrapper > ) => {
117141 return htmlRunner . run ( {
118142 url,
119143 scrapper : async ( args ) => {
@@ -126,8 +150,13 @@ const domRunner = new Runner('dom', async ({url, scrapper, options= {}}: RunnerA
126150 options
127151 } ) ;
128152} ) ;
129- export type UrlRunnerScrapper = ( args : { url : string , scrapper : UrlRunnerScrapper , runners : RunnerList } ) => any ;
130- const urlRunner = new Runner ( 'url' , async ( { url, scrapper, options= { } } : RunnerArgs < UrlRunnerScrapper > ) => {
153+ export type UrlRunnerScrapper = ( args : {
154+ url : string ,
155+ scrapper : UrlRunnerScrapper ,
156+ runners : RunnerList
157+ } ) => any ;
158+ const urlRunner = new Runner ( 'url' ,
159+ async ( { url, scrapper, options= { } } : RunnerArgs < UrlRunnerScrapper > ) => {
131160 return scrapper ( {
132161 url,
133162 scrapper,
0 commit comments