Skip to content

Commit

Permalink
add callback/errback to requests from recaptcha mware
Browse files Browse the repository at this point in the history
  • Loading branch information
mxsnq committed Jan 19, 2024
1 parent de56eac commit 6c82cdb
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions scrapypuppeteer/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,14 +312,17 @@ def process_response(self,
return response

# Any puppeteer response besides RecaptchaSolver's PuppeteerResponse
return self._solve_recaptcha(response)
return self._solve_recaptcha(request, response)

def _solve_recaptcha(self, response):
def _solve_recaptcha(self, request, response):
self._page_responses[response.page_id] = response # Saving main response to return it later

recaptcha_solver = RecaptchaSolver(solve_recaptcha=self.recaptcha_solving,
close_on_empty=self.__is_closing(response, remove_request=False))
return response.follow(recaptcha_solver,
callback=request.callback,
cb_kwargs=request.cb_kwargs,
errback=request.errback,
meta={'_captcha_solving': True},
close_page=False)

Expand All @@ -339,6 +342,7 @@ def _submit_recaptcha(self, request, response, spider):
return self.__gen_response(response)
return response.follow(action=submitting,
callback=request.callback,
cb_kwargs=request.cb_kwargs,
errback=request.errback,
close_page=self.__is_closing(response),
meta={'_captcha_submission': True})
Expand Down

0 comments on commit 6c82cdb

Please sign in to comment.