Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Please show another Exit Method ,ths #11

Open
liuzeng01 opened this issue May 2, 2020 · 1 comment
Open

Please show another Exit Method ,ths #11

liuzeng01 opened this issue May 2, 2020 · 1 comment

Comments

@liuzeng01
Copy link

I had read the example spider, it used the signal chan as the exit method .But it's not very helpfully. Can you show more exit method ? For example , if the spider having done all the scrapy works ,it would exit automatically ?

@zhengchun
Copy link
Contributor

func main() {
	startURLs := []string{
		"http://dmoztools.net/Computers/Programming/Languages/Python/Books/",
		"http://dmoztools.net/Computers/Programming/Languages/Python/Resources/",
	}

	quitCh := make(chan struct{})
	crawler := &antch.Crawler{Exit: quitCh}
	spdier := antch.HandlerFunc(func(c chan<- antch.Item, _ *http.Response) {
		c <- nil
	})
	crawler.Handle("*", spdier)

	works := 0
	crawler.UsePipeline(func(next antch.PipelineHandler) antch.PipelineHandler {
		return antch.PipelineHandlerFunc(func(v antch.Item) {
			works++
			if works == len(startURLs) {
				close(quitCh)
			}
		})
	})

	go func() {
		crawler.StartURLs(startURLs)
	}()
	<-crawler.Exit
	fmt.Println("all done")
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants