From 8e80593d639266e39dd1c23668893391cca09c57 Mon Sep 17 00:00:00 2001 From: Shinku <17696928+Shinku-Chen@users.noreply.github.com> Date: Mon, 8 Apr 2024 18:04:48 +0800 Subject: [PATCH] retry redirect to AlreadyVisitedUrl will loop error --- colly.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/colly.go b/colly.go index ca0ab41e..22cbf2f4 100644 --- a/colly.go +++ b/colly.go @@ -654,10 +654,10 @@ func (c *Collector) scrape(u, method string, depth int, requestData io.Reader, c // note: once 1.13 is minimum supported Go version, // replace this with http.NewRequestWithContext if c.Context == nil { - req = req.WithContext(context.WithValue(context.Background(), CheckRevisitKey, checkRevisit)) - } else { - req = req.WithContext(context.WithValue(c.Context, CheckRevisitKey, checkRevisit)) + c.Context = context.Background() } + req = req.WithContext(context.WithValue(c.Context, CheckRevisitKey, checkRevisit)) + if err := c.requestCheck(parsedURL, method, req.GetBody, depth, checkRevisit); err != nil { return err }