From bae927d15cd7dcab1f8d4064c2c09ba05566806b Mon Sep 17 00:00:00 2001 From: AndrewKorzh <92707967+AndrewKorzh@users.noreply.github.com> Date: Wed, 7 Aug 2024 19:43:18 +0300 Subject: [PATCH] add authorization --- scrapypuppeteer/actions.py | 33 +++++++++++++++++++++++++++++++++ scrapypuppeteer/middleware.py | 3 ++- 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/scrapypuppeteer/actions.py b/scrapypuppeteer/actions.py index 141a703..c153dd6 100644 --- a/scrapypuppeteer/actions.py +++ b/scrapypuppeteer/actions.py @@ -70,6 +70,39 @@ def payload(self): "navigationOptions": self.navigation_options, "waitOptions": self.wait_options, } + + +class Authorization(PuppeteerServiceAction): + + endpoint = "authorization" + + def __init__( + self, login_selector: str, + password_selector: str, + submit_button_selector: str, + login: str, + password: str, + entry_wait_options: dict = None, + wait_options: dict = None + ): + self.login_selector = login_selector + self.password_selector = password_selector + self.login = login + self.password = password + self.submit_button_selector = submit_button_selector + self.entry_wait_options = entry_wait_options + self.wait_options = wait_options + + def payload(self): + return { + "loginSelector": self.login_selector, + "passwordSelector": self.password_selector, + "submitButtonSelector": self.submit_button_selector, + "login": self.login, + "password": self.password, + "entryWaitOptions": self.entry_wait_options, + "waitOptions": self.wait_options, + } class GoForward(PuppeteerServiceAction): diff --git a/scrapypuppeteer/middleware.py b/scrapypuppeteer/middleware.py index 6907ae0..693c48d 100644 --- a/scrapypuppeteer/middleware.py +++ b/scrapypuppeteer/middleware.py @@ -20,6 +20,7 @@ Screenshot, Scroll, CustomJsAction, + Authorization ) from scrapypuppeteer.response import ( PuppeteerResponse, @@ -228,7 +229,7 @@ def _form_response( @staticmethod def _get_response_class(request_action): - if isinstance(request_action, (GoTo, GoForward, GoBack, Click, Scroll)): + if isinstance(request_action, (GoTo, GoForward, GoBack, Click, Scroll, Authorization)): return PuppeteerHtmlResponse if isinstance(request_action, Screenshot): return PuppeteerScreenshotResponse