From ac22388594c4a13f3ac14be8eaeb656218937d9e Mon Sep 17 00:00:00 2001 From: theblackturtle Date: Fri, 7 Feb 2020 22:36:23 +0700 Subject: [PATCH] add OnError handle --- core/crawler.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/core/crawler.go b/core/crawler.go index 750f728..c903967 100644 --- a/core/crawler.go +++ b/core/crawler.go @@ -279,13 +279,22 @@ func (crawler *Crawler) Start() { u := response.Request.URL.String() if crawler.domainRe.MatchString(u) { outputFormat := fmt.Sprintf("[url] - [code-%d] - %s", response.StatusCode, u) - //Logger.Info(outputFormat + "\n") fmt.Println(outputFormat) if crawler.Output != nil { crawler.Output.WriteToFile(outputFormat) } } }) + + crawler.C.OnError(func(response *colly.Response, err error) { + u := response.Request.URL.String() + outputFormat := fmt.Sprintf("[url] - [code-%d] - %s", response.StatusCode, u) + fmt.Println(outputFormat) + if crawler.Output != nil { + crawler.Output.WriteToFile(outputFormat) + } + }) + _ = crawler.C.Visit(crawler.site) }