foreign-sapphire•4y ago
How to make crawlee try to refetch?
If the return value of the http api I crawl does not meet expectations, but http status is 200
How can I mark this request as a failure and let crawlee get it again with next proxy?
7 Replies
xenial-black•4y ago
From what I understood, you want to make a request based on the data you receive from the initial request? If yes, then you can use the context object in the requestHandler to make a new request or enqueue a new request like this.
like-gold•4y ago
wouldnt it make crawlee think its a duplicate?
xenial-black•4y ago
Good point, from my understanding it shouldn't be a problem if you're using
sendRequest for the new request, but if you're using crawler.addRequests you will have to manually generate a uniqueKey for each RequestOptions to prevent it from being marked as duplicate. I have updated my snippet to show how to do this.like-gold•4y ago
thanks
throw new Error("REASONOFRETRY")You can also do
session.retire() before the throw to ensure it is discarded. Normally, it only increases error score for itforeign-sapphireOP•4y ago
I got it, thanks all 💓