From 137f2d556282182e84a83ef0a7583ec3ec7bec07 Mon Sep 17 00:00:00 2001 From: work Date: Tue, 27 May 2025 13:53:20 +0800 Subject: [PATCH] =?UTF-8?q?m=E7=AB=AF=E5=88=A4=E6=96=AD=E6=98=AF=E5=90=A6?= =?UTF-8?q?=E6=9C=89=E6=89=8B=E6=9C=BAapp=E9=AA=8C=E8=AF=81,=20=E6=9B=B4?= =?UTF-8?q?=E6=94=B9=E7=99=BB=E5=BD=95=E6=88=90=E5=8A=9F=E9=A1=B5=E9=9D=A2?= =?UTF-8?q?=E7=9A=84=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- spider/task.py | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/spider/task.py b/spider/task.py index 196ecc9..aa6ceb2 100644 --- a/spider/task.py +++ b/spider/task.py @@ -1385,10 +1385,12 @@ def playwright_m_login(username, password, code_2fa=None): time.sleep(1) page.click('div[aria-label="Log in"]') - success_login_selector = 'span:has-text("Check your notifications on another device")' + success_login_selector1 = 'span:has-text("Check your notifications on another device")' + success_login_selector2 = 'span:has-text("Go to your authentication app")' failed_login_selector = 'div[data-bloks-name="bk.components.dialog.Dialog"] > div[aria-label="Wrong Credentials"] > div:nth-child(1)' # 等成功或失败两个选择的其中一个 - page.wait_for_selector(f'{success_login_selector}, {failed_login_selector}', timeout=60000) + page.wait_for_selector(f'{success_login_selector1},{success_login_selector2}, {failed_login_selector}', + timeout=60000) # 判断是否失败 failed_login = page.query_selector(failed_login_selector) @@ -1397,18 +1399,21 @@ def playwright_m_login(username, password, code_2fa=None): logger.info(f"用户名:{username} 密码错误 {failed_login.text_content()}") raise OperationFailed(failed_login.text_content()) - # 点击尝试另一种方式验证账号 - page.query_selector('div[role="button"][aria-label="Try another way"]').click() + # 判断是否有多重验证 + success_login1 = page.query_selector(success_login_selector1) + if success_login1: + # 点击尝试另一种方式验证账号 + page.query_selector('div[role="button"][aria-label="Try another way"]').click() - # 点击选择app验证 - page.wait_for_selector( - 'span[data-bloks-name="bk.components.TextSpan"]:has-text("Authentication app")').click() + # 点击选择app验证 + page.wait_for_selector( + 'span[data-bloks-name="bk.components.TextSpan"]:has-text("Authentication app")').click() - # 点击继续 - page.query_selector('div[role="button"][aria-label="Continue"]').click() + # 点击继续 + page.query_selector('div[role="button"][aria-label="Continue"]').click() # 等待页面 - page.wait_for_selector('span:has-text("Go to your authentication app")') + page.wait_for_selector('span:has-text("Go to your authentication app")', timeout=60000) # 输入2faCode auth_code = pyotp.TOTP(code_2fa).now() @@ -1418,7 +1423,7 @@ def playwright_m_login(username, password, code_2fa=None): page.query_selector('div[role="button"][aria-label="Continue"]').click() # 等待登录成功 - page.wait_for_selector('span:has-text("Save your login info?")', timeout=60000) + page.wait_for_selector('img[data-bloks-name="bk.components.Image"][src*=".fbcdn.net/v/t"]',timeout=60000) # 成功 logger.info(f"用户名:{username} 账号密码正确")