修复登录标题可能有的其他内容, 修复登录继续按钮可能获取到多个

This commit is contained in:
work
2025-05-08 11:59:12 +08:00
parent 4ad1eed171
commit d6cac6d7d5

View File

@@ -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