2fa验证重试中点击后再判断
This commit is contained in:
@@ -877,13 +877,13 @@ def login_with_2fa_retry(page, code_2fa, max_retries=3):
|
|||||||
)
|
)
|
||||||
code_input.fill(auth_code)
|
code_input.fill(auth_code)
|
||||||
|
|
||||||
# 等待可能的验证结果
|
# 点击继续
|
||||||
page.wait_for_timeout(2000) # 等待2秒让系统处理
|
page.query_selector('div[role="button"][aria-label="Continue"]').click()
|
||||||
|
|
||||||
# 检查是否出现错误信息
|
# 检查是否出现错误信息
|
||||||
|
try:
|
||||||
error_element = page.wait_for_selector(
|
error_element = page.wait_for_selector(
|
||||||
'span:has-text("This code doesn’t work. Check it’s correct or try a new one.")', timeout=10000)
|
'span:has-text("This code doesn’t work. Check it’s correct or try a new one.")', timeout=3000)
|
||||||
|
|
||||||
if error_element and error_element.is_visible():
|
if error_element and error_element.is_visible():
|
||||||
print("2FA验证码错误,准备重试...")
|
print("2FA验证码错误,准备重试...")
|
||||||
retry_count += 1
|
retry_count += 1
|
||||||
@@ -897,16 +897,10 @@ def login_with_2fa_retry(page, code_2fa, max_retries=3):
|
|||||||
print(f"等待 {wait_time} 秒后重试...")
|
print(f"等待 {wait_time} 秒后重试...")
|
||||||
time.sleep(wait_time)
|
time.sleep(wait_time)
|
||||||
continue
|
continue
|
||||||
else:
|
except TimeoutError:
|
||||||
logger.info("2FA验证成功!")
|
logger.info("2FA验证成功!")
|
||||||
return True
|
return True
|
||||||
|
|
||||||
except TimeoutError:
|
|
||||||
logger.info("查找输入框超时,可能是页面加载问题")
|
|
||||||
retry_count += 1
|
|
||||||
if retry_count < max_retries:
|
|
||||||
time.sleep(3)
|
|
||||||
continue
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.info(f"2FA验证发生未知错误: {e}")
|
logger.info(f"2FA验证发生未知错误: {e}")
|
||||||
retry_count += 1
|
retry_count += 1
|
||||||
@@ -1009,8 +1003,6 @@ def playwright_m_login(username, password, code_2fa=None):
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"2FA验证失败: {e}", exc_info=True)
|
logger.error(f"2FA验证失败: {e}", exc_info=True)
|
||||||
raise OperationFailed(f"2FA验证失败: {e}")
|
raise OperationFailed(f"2FA验证失败: {e}")
|
||||||
# 点击继续
|
|
||||||
page.query_selector('div[role="button"][aria-label="Continue"]').click()
|
|
||||||
|
|
||||||
# 等待登录成功, 账号被检测自动化程序会卡在这里. 直接忽略报错
|
# 等待登录成功, 账号被检测自动化程序会卡在这里. 直接忽略报错
|
||||||
try:
|
try:
|
||||||
@@ -1145,7 +1137,7 @@ if __name__ == '__main__':
|
|||||||
# # # 视频链接的帖子点赞
|
# # # 视频链接的帖子点赞
|
||||||
# print(playwright_like(cookies, "https://www.facebook.com/groups/1070754870427928/permalink/1873461830157224/"))
|
# print(playwright_like(cookies, "https://www.facebook.com/groups/1070754870427928/permalink/1873461830157224/"))
|
||||||
#
|
#
|
||||||
cookies = playwright_m_login('61582494086321', '47a67lDCC8', '4AQBIGCZDKKZ4WKKDZQIOAAKJ2A4QACR')
|
cookies = playwright_m_login('61583069571290', '47lfsryRmI', 'IJ6YM5MX6HEMRRIDSNUMSCEBJEIHVH3R')
|
||||||
print(cookies)
|
print(cookies)
|
||||||
# pass
|
# pass
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user