keep state and continue
This commit is contained in:
		
							
								
								
									
										73
									
								
								readme.md
									
									
									
									
									
								
							
							
						
						
									
										73
									
								
								readme.md
									
									
									
									
									
								
							| @ -50,17 +50,14 @@ function (itemsSelector:string, fieldSelectors:string[], urls:string[]) | ||||
| function (itemsSelector:string, fieldSelectors:string[], urls:ExtractResult) | ||||
| ``` | ||||
|  | ||||
| ## Advanced Usage | ||||
| ## Stop Tasks | ||||
|  | ||||
| ### Stop Tasks | ||||
| The only way to stop tasks before its finish, is `Closing the target tab`. | ||||
|  | ||||
| Tasks wait for their target elements' appearance, given some elements were loaded asynchronously. | ||||
| > Tasks wait for their target elements' appearance, given some elements were loaded asynchronously.   | ||||
| > If you typed wrong selectors, the task waits forever for  elements which don't exists. | ||||
|  | ||||
| But if you typed wrong selectors, the task waits forever for  elements which don't exists. | ||||
|  | ||||
| The only way to stop tasks before its finish, is `Closing the host tab`. | ||||
|  | ||||
| ### Extract Attributes. | ||||
| ## Extract Attributes. | ||||
|  | ||||
| e.g.: link text and target (use 'selector@attribute') | ||||
|  | ||||
| @ -68,20 +65,43 @@ e.g.: link text and target (use 'selector@attribute') | ||||
| new Extractor().task('.item', ['a', 'a@href']).start(); | ||||
| ``` | ||||
|  | ||||
| ## Advanced Usage | ||||
|  | ||||
| ### Use Task Chain. | ||||
|  | ||||
| e.g.: Collect links from `http://sample.com/abc`, then, Extract data of each link | ||||
|  | ||||
| ```js | ||||
| new Extractor() | ||||
|     .task('.search-list-item', ['a@href'], ["http://sample.com/abc"]) | ||||
| e = new Extractor() | ||||
| e.task('.search-list-item', ['a@href'], ["http://sample.com/abc"]) | ||||
|     .task('list-item', ["a.title", "p.content"]) | ||||
|     .start(); | ||||
| ``` | ||||
|  | ||||
| ### Continue Tasks | ||||
|  | ||||
| You can always continue tasks (with following), even it stops in the middle of a task: | ||||
|  | ||||
| ```js | ||||
| e.start() | ||||
| ``` | ||||
|  | ||||
| The `Extractor` kept the state of last execution, and starts from where it stopped. | ||||
|  | ||||
| ### Restart Tasks | ||||
|  | ||||
| What should I do, if I don't like to continue from last state, but restart from certain task? | ||||
|  | ||||
| ```js | ||||
| // restart all tasks | ||||
| e.restart(0) | ||||
| // restart from 2nd task | ||||
| e.restart(1) | ||||
| ``` | ||||
|  | ||||
| ### Save Result of Any Task | ||||
|  | ||||
| To a multiple task (chain) Extractor `e`: | ||||
| To a multiple task Extractor `e`: | ||||
|  | ||||
| ```js | ||||
| e = new Extractor() | ||||
| @ -98,37 +118,12 @@ Incase you want to save it again, use: | ||||
| e.save() | ||||
| ``` | ||||
|  | ||||
| You may want to save another task's result, other than the final: | ||||
| To save another task result, other than the final one: | ||||
|  | ||||
| ```js | ||||
| // save the result of first task | ||||
| // to the example above, that is a list of urls | ||||
| e.save(0) | ||||
| // save the result of second task | ||||
| e.save(1) | ||||
| ``` | ||||
|  | ||||
| ### Restart Tasks | ||||
|  | ||||
| In cases some later task fails, you don't need to restart all task. | ||||
|  | ||||
| Here we have 2 tasks: | ||||
|  | ||||
| ```js | ||||
| e = new Extractor() | ||||
| e.task('.search-list-item', ['a@href'], ["http://sample.com/abc"]) | ||||
|     .task('list-item', ["a.title", "p.content"]) | ||||
|     .start(); | ||||
| ``` | ||||
|  | ||||
| Suppose the second task fails, we can restart and continue from the task 2: | ||||
|  | ||||
| ```js | ||||
| e.restart(2); | ||||
| ``` | ||||
|  | ||||
| If you'd like restart all task, use: | ||||
|  | ||||
| ```js | ||||
| e.start(); | ||||
| // or | ||||
| e.restart(); | ||||
| ``` | ||||
		Reference in New Issue
	
	Block a user