From d6cac6d7d5e54e1ecaf2a86ba10cdfc8b5ffada3 Mon Sep 17 00:00:00 2001 From: work Date: Thu, 8 May 2025 11:59:12 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E7=99=BB=E5=BD=95=E6=A0=87?= =?UTF-8?q?=E9=A2=98=E5=8F=AF=E8=83=BD=E6=9C=89=E7=9A=84=E5=85=B6=E4=BB=96?= =?UTF-8?q?=E5=86=85=E5=AE=B9,=20=E4=BF=AE=E5=A4=8D=E7=99=BB=E5=BD=95?= =?UTF-8?q?=E7=BB=A7=E7=BB=AD=E6=8C=89=E9=92=AE=E5=8F=AF=E8=83=BD=E8=8E=B7?= =?UTF-8?q?=E5=8F=96=E5=88=B0=E5=A4=9A=E4=B8=AA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- spider/task.py | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/spider/task.py b/spider/task.py index 1a3485c..67ed23e 100644 --- a/spider/task.py +++ b/spider/task.py @@ -1133,6 +1133,15 @@ def playwright_check_account_cookies(cookies): return {} +def get_login_continue_btn(page): + bs = page.query_selector_all('//span[text()="Continue"]') + for b in bs: + if b.is_visible() and b.is_enabled(): + return b + + return None + + def playwright_login(username, password, code_2fa=None): path = os.path.join(BASE_PATH, 'chrome', '130-0008', 'chrome.exe') with lock: @@ -1194,7 +1203,12 @@ def playwright_login(username, password, code_2fa=None): if h2 is None: raise OperationFailed('页面有误') else: - if h2.text_content() != "Check your notifications on another device": + text_contexts = [ + "Go to your authentication app", + "Check your notifications on another device" + ] + + if not h2.text_content() in text_contexts: raise OperationFailed("操作失败") auth_span = page.query_selector('//span[text()="Try Another Way" or text()="Try another way"]') if auth_span: @@ -1202,8 +1216,14 @@ def playwright_login(username, password, code_2fa=None): raise OperationFailed('缺少2FA密钥') auth_code = pyotp.TOTP(code_2fa).now() auth_span.click() + time.sleep(1) page.click('//div[text()="Authentication app"]') - page.click('//span[text()="Continue"]') + time.sleep(1) + # 可能会有多个Continue + btn = get_login_continue_btn(page) + if btn is None: + raise OperationFailed("操作失败") + btn.click() time.sleep(1) page.locator('//label[text()="Code"]/preceding-sibling::input').fill(auth_code) page.click('//span[text()="Continue"]') @@ -1258,8 +1278,8 @@ if __name__ == '__main__': # # lastname='Keals', # # image_key='rg.jpg' # ) - cookies = '{"c_user":"61565823476070","datr":"q13hZowje6bbViFxECQpYyp8","fr":"01C6Lt4VArm5hELvx.AWXg75HOo-QNJgbiDl8qFtw_5lc.Bm4V2r..AAA.0.0.Bm4V25.AWWHzUeMTuI","m_pixel_ratio":"1.875","sb":"q13hZgJARsRIDmNJG8xUauAe","wd":"384x686","xs":"50%3A8luhgQ-Ea0vnhg%3A2%3A1726045627%3A-1%3A-1"}' - playwright_check_account_cookies(cookies) - # cookies = playwright_login('61575694132528', '@Badhon@20', 'LK3UVPADNOEGWIWPBAWWVGDPCMJOZN7M') + # cookies = '{"c_user":"61565823476070","datr":"q13hZowje6bbViFxECQpYyp8","fr":"01C6Lt4VArm5hELvx.AWXg75HOo-QNJgbiDl8qFtw_5lc.Bm4V2r..AAA.0.0.Bm4V25.AWWHzUeMTuI","m_pixel_ratio":"1.875","sb":"q13hZgJARsRIDmNJG8xUauAe","wd":"384x686","xs":"50%3A8luhgQ-Ea0vnhg%3A2%3A1726045627%3A-1%3A-1"}' + # playwright_check_account_cookies(cookies) + cookies = playwright_login('61575975148121', 'Mu1711rstu1999', 'JNCCTXB34EP5ME6RU6RND6SHBQ6KATAR') # print(cookies) pass