helper function $
This commit is contained in:
		
							
								
								
									
										40
									
								
								readme.md
									
									
									
									
									
								
							
							
						
						
									
										40
									
								
								readme.md
									
									
									
									
									
								
							| @ -5,7 +5,7 @@ DataExtracter helps you quickly extract data from any web pages. | ||||
|  | ||||
| All you need to do is: | ||||
|  | ||||
| - Find out the selectors (JQuery selectors) for target data | ||||
| - Find out the selectors for target data | ||||
| - Type scripts in the console of `extension backgroud page`, as introduced bellow. | ||||
|  | ||||
|   | ||||
| @ -14,40 +14,40 @@ All you need to do is: | ||||
|  | ||||
| Extract current page | ||||
| ```js | ||||
| new Extractor().task(".list-item", ["a.title", "p.content"]).start(); | ||||
| $('.item', ['a', 'a@href']); | ||||
| ``` | ||||
|  | ||||
| Extract multiple pages (1-10, interval 1) | ||||
|  | ||||
| ```js | ||||
| new Extractor().task(".list-item", ["a.title", "p.content"],"http://sample.com/?pn=${page}", 1, 10, 1).start(); | ||||
| $('.item', ['a', 'a@href'],"http://sample.com/?pn=${page}", 1, 10, 1); | ||||
| ``` | ||||
|  | ||||
| Extract multiple urls (list) | ||||
|  | ||||
| ```js | ||||
| new Extractor().task(".list-item", ["a.title", "p.content"],["http://sample.com/abc","http://sample.com/xyz"]).start(); | ||||
| $('.item', ['a', 'a@href'],["http://sample.com/abc","http://sample.com/xyz"]); | ||||
| ``` | ||||
|  | ||||
| Extract specified pages (1,3,5) | ||||
|  | ||||
| ```js | ||||
| new Extractor().task(".list-item", ["a.title", "p.content"], "http://sample.com/?pn=${page}", [1, 3, 5]).start(); | ||||
| $('.item', ['a', 'a@href'], "http://sample.com/?pn=${page}", [1, 3, 5]); | ||||
| ``` | ||||
|  | ||||
| ## Extractor.task() Signitures | ||||
| ## Task Call Signitures | ||||
|  | ||||
| ```ts | ||||
| // a task extracting data from current page | ||||
| task(itemsSelector:string, fieldSelectors:string[]) | ||||
| // a task extracting data from a range of pages | ||||
| task(itemsSelector:string, fieldSelectors:string[], urlTemplate:string, from:number, to:number, interval:number) | ||||
| // a task extracting data from a list of pages | ||||
| task(itemsSelector:string, fieldSelectors:string, urlTemplate:string, pages:number[]) | ||||
| // a task extracting data from a list of pages | ||||
| task(itemsSelector:string, fieldSelectors:string[], urls:string[]) | ||||
| // a task extracting data of urls which extracted from last task result | ||||
| task(itemsSelector:string, fieldSelectors:string[], urls:ExtractResult) | ||||
| // extract data from current page | ||||
| function (itemsSelector:string, fieldSelectors:string[]) | ||||
| // extract data from a range of pages | ||||
| function (itemsSelector:string, fieldSelectors:string[], urlTemplate:string, from:number, to:number, interval:number) | ||||
| // extract data from a list of pages | ||||
| function (itemsSelector:string, fieldSelectors:string, urlTemplate:string, pages:number[]) | ||||
| // extract data from a list of pages | ||||
| function (itemsSelector:string, fieldSelectors:string[], urls:string[]) | ||||
| // extract data of urls which extracted from last task result | ||||
| function (itemsSelector:string, fieldSelectors:string[], urls:ExtractResult) | ||||
| ``` | ||||
|  | ||||
| ## Advanced Usage | ||||
| @ -65,7 +65,7 @@ The only way to stop tasks before its finish, is `Closing the host tab`. | ||||
| e.g.: link text and target (use 'selector@attribute') | ||||
|  | ||||
| ```js | ||||
| new Extractor().task('.list-item', ['a.title', 'a.title@href']).start(); | ||||
| new Extractor().task('.item', ['a', 'a@href']).start(); | ||||
| ``` | ||||
|  | ||||
| ### Use Task Chain. | ||||
| @ -74,7 +74,7 @@ e.g.: Collect links from `http://sample.com/abc`, then, Extract data of each lin | ||||
|  | ||||
| ```js | ||||
| new Extractor() | ||||
|     .task('.search-list-item', ['.item a@href'], ["http://sample.com/abc"]) | ||||
|     .task('.search-list-item', ['a@href'], ["http://sample.com/abc"]) | ||||
|     .task('list-item', ["a.title", "p.content"]) | ||||
|     .start(); | ||||
| ``` | ||||
| @ -85,7 +85,7 @@ To a multiple task (chain) Extractor `e`: | ||||
|  | ||||
| ```js | ||||
| e = new Extractor() | ||||
| e.task('.search-list-item', ['.item a@href'], ["http://sample.com/abc"]) | ||||
| e.task('.search-list-item', ['a@href'], ["http://sample.com/abc"]) | ||||
|     .task('list-item', ["a.title", "p.content"]) | ||||
|     .start(); | ||||
| ``` | ||||
| @ -114,7 +114,7 @@ Here we have 2 tasks: | ||||
|  | ||||
| ```js | ||||
| e = new Extractor() | ||||
| e.task('.search-list-item', ['.item a@href'], ["http://sample.com/abc"]) | ||||
| e.task('.search-list-item', ['a@href'], ["http://sample.com/abc"]) | ||||
|     .task('list-item', ["a.title", "p.content"]) | ||||
|     .start(); | ||||
| ``` | ||||
|  | ||||
		Reference in New Issue
	
	Block a user