From ca9a37d12afe1e46b0fba1186b673f596f395677 Mon Sep 17 00:00:00 2001 From: Edward <73746306+WangEdward@users.noreply.github.com> Date: Thu, 15 Feb 2024 16:19:20 +0000 Subject: [PATCH 1/2] =?UTF-8?q?fix:=202fa=20=E5=8F=98=E9=87=8F=E5=90=8D?= =?UTF-8?q?=E5=86=B2=E7=AA=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/helper/cookie.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/helper/cookie.py b/app/helper/cookie.py index e5ec88c0..8187256e 100644 --- a/app/helper/cookie.py +++ b/app/helper/cookie.py @@ -111,10 +111,10 @@ class CookieHelper: if not password_xpath: return None, None, "未找到密码输入框" # 处理二步验证码 - two_step_code = TwoFactorAuth(two_step_code).get_code() + otp_code = TwoFactorAuth(two_step_code).get_code() # 查找二步验证码输入框 twostep_xpath = None - if two_step_code: + if otp_code: for xpath in self._SITE_LOGIN_XPATH.get("twostep"): if html.xpath(xpath): twostep_xpath = xpath @@ -152,7 +152,7 @@ class CookieHelper: page.fill(password_xpath, password) # 输入二步验证码 if twostep_xpath: - page.fill(twostep_xpath, two_step_code) + page.fill(twostep_xpath, otp_code) # 识别验证码 if captcha_xpath and captcha_img_url: captcha_element = page.query_selector(captcha_xpath) From bb7d262ea39473a42d8c7e08b14521ca33400937 Mon Sep 17 00:00:00 2001 From: Edward <73746306+WangEdward@users.noreply.github.com> Date: Thu, 15 Feb 2024 16:39:14 +0000 Subject: [PATCH 2/2] feat: m-team 2fa --- app/helper/cookie.py | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/app/helper/cookie.py b/app/helper/cookie.py index 8187256e..150f7e91 100644 --- a/app/helper/cookie.py +++ b/app/helper/cookie.py @@ -52,7 +52,8 @@ class CookieHelper: ], "twostep": [ '//input[@name="two_step_code"]', - '//input[@name="2fa_secret"]' + '//input[@name="2fa_secret"]', + '//input[@name="otp"]' ] } @@ -179,6 +180,24 @@ class CookieHelper: except Exception as e: logger.error(f"仿真登录失败:{str(e)}") return None, None, f"仿真登录失败:{str(e)}" + # 对于某二次验证码为单页面的站点,输入二次验证码 + if "verify" in page.url: + if not otp_code: + return None, None, "需要二次验证码" + html = etree.HTML(page.content()) + for xpath in self._SITE_LOGIN_XPATH.get("twostep"): + if html.xpath(xpath): + try: + # 刷新一下 2fa code + otp_code = TwoFactorAuth(two_step_code).get_code() + page.fill(xpath, otp_code) + # 登录按钮 xpath 理论上相同,不再重复查找 + page.click(submit_xpath) + page.wait_for_load_state("networkidle", timeout=30 * 1000) + except Exception as e: + logger.error(f"二次验证码输入失败:{str(e)}") + return None, None, f"二次验证码输入失败:{str(e)}" + break # 登录后的源码 html_text = page.content() if not html_text: