Skip to content

Instantly share code, notes, and snippets.

@chavarera
Created March 2, 2021 10:15
Show Gist options
  • Save chavarera/d1ad43481d5cbe19e803fed056ea0270 to your computer and use it in GitHub Desktop.
Save chavarera/d1ad43481d5cbe19e803fed056ea0270 to your computer and use it in GitHub Desktop.
scrapy request delay middleware
class RequestDelayMiddleware(object):
def process_request(self, request, spider):
# Add delay_by key in meta
delay_s = request.meta.get('delay_by', None)
if not delay_s:
return
deferred = Deferred()
reactor.callLater(delay_s, deferred.callback, None)
return deferred
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment