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

retry redirect to AlreadyVisitedUrl will loop error #805

Open
Shinku-Chen opened this issue Jan 30, 2024 · 1 comment
Open

retry redirect to AlreadyVisitedUrl will loop error #805

Shinku-Chen opened this issue Jan 30, 2024 · 1 comment

Comments

@Shinku-Chen
Copy link

Shinku-Chen commented Jan 30, 2024

func TestRedirectErrorRetry(t *testing.T) {
	ts := newTestServer()
	defer ts.Close()
	c := NewCollector()
	c.OnError(func(r *Response, err error) {
		if r.Ctx.Get("notFirst") == "" {
			r.Ctx.Put("notFirst", "first")
			_ = r.Request.Retry()
			return
		}
		t.Error("loop")
	})
	c.OnResponse(func(response *Response) {
		println(1)
	})
	c.Visit(ts.URL + "/redirected/")
	c.Visit(ts.URL + "/redirect")
}
@Shinku-Chen
Copy link
Author

add config

c.OnError(func(response *colly.Response, err error) {
var alreadyVisitedError *colly.AlreadyVisitedError
if errors.As(err, &alreadyVisitedError) {
response.Request.URL = &url.URL{} //防止在retry的时候出现已经访问的错误
}
})

to forbidden retry a Visited url

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

1 participant