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

Option not to pass Request Context to the Next Request #742

Open
sundarv85 opened this issue Nov 30, 2022 · 0 comments
Open

Option not to pass Request Context to the Next Request #742

sundarv85 opened this issue Nov 30, 2022 · 0 comments

Comments

@sundarv85
Copy link

I'm using Request Context to store information about the parsed body on various c.OnHTML callbacks..

So what happens is, if I use the e.Request.Visit() for following up on hrefs, then the request context is also being passed. I wanted to avoid this. So instead of using e.Request.Visit() I used c.Visit() directly. This made sure that I got new context for each request.

However, I would like to use the MaxDepth option as well. But that only works if I use the e.Request.Visit().

It would work for me to use the e.Request.Visit() but give new context for each request. This is currently not possible. Is that correct?

If yes, this feature request would be great to have as a configuration option - to determine if the request context has to be passed along or not..

For now, I have manually made the change for local purposes..

index 6beef834..524bb77c 100644
--- a/vendor/github.com/gocolly/colly/v2/request.go
+++ b/vendor/github.com/gocolly/colly/v2/request.go
@@ -117,7 +117,7 @@ func (r *Request) AbsoluteURL(u string) string {
 // request and preserves the Context of the previous request.
 // Visit also calls the previously provided callbacks
 func (r *Request) Visit(URL string) error {
-	return r.collector.scrape(r.AbsoluteURL(URL), "GET", r.Depth+1, nil, r.Ctx, nil, true)
+	return r.collector.scrape(r.AbsoluteURL(URL), "GET", r.Depth+1, nil, nil, nil, true)
 }
 
 // HasVisited checks if the provided URL has been visited```
@sundarv85 sundarv85 changed the title Option not to oass Request Context to the Next Request Option not to pass Request Context to the Next Request Nov 30, 2022
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