Skip to content

Commit

Permalink
add OnError handle
Browse files Browse the repository at this point in the history
  • Loading branch information
theblackturtle committed Feb 7, 2020
1 parent d981d45 commit ac22388
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion core/crawler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down

0 comments on commit ac22388

Please sign in to comment.