修复m登录可能会跳到首页和操作超时的问题
This commit is contained in:
@@ -1185,7 +1185,7 @@ def retry_goto(page: "Page", url: str, max_retries: int = 3, retry_delay: int =
|
||||
|
||||
# Make the synchronous goto call within the try block
|
||||
# Use wait_until='load' as in your traceback, or adjust if needed
|
||||
page.goto(url, timeout=30000) # Use the synchronous call
|
||||
page.goto(url, timeout=30000, wait_until="domcontentloaded") # Use the synchronous call
|
||||
|
||||
print(f"Successfully navigated to {url} on attempt {attempt + 1}")
|
||||
break # Navigation was successful, exit the retry loop
|
||||
@@ -1350,14 +1350,13 @@ def playwright_m_login(username, password, code_2fa=None):
|
||||
},
|
||||
])
|
||||
page = context.new_page()
|
||||
url = 'https://m.facebook.com'
|
||||
url = 'https://m.facebook.com/login'
|
||||
retry_goto(page, url)
|
||||
page.locator('//input[@id="m_login_email"]').type(username, delay=30)
|
||||
time.sleep(random.randint(1, 3))
|
||||
page.locator('//input[@id="m_login_password"]').type(password, delay=30)
|
||||
time.sleep(random.randint(1, 3))
|
||||
page.click('//div[@aria-label="Log in"]')
|
||||
page.wait_for_load_state()
|
||||
time.sleep(random.randint(3, 5))
|
||||
|
||||
success_login_selector = '//span[text()="Check your notifications on another device"]'
|
||||
@@ -1369,9 +1368,11 @@ def playwright_m_login(username, password, code_2fa=None):
|
||||
failed_login = page.query_selector(failed_login_selector)
|
||||
if failed_login:
|
||||
# 登录失败, 返回失败信息
|
||||
logger.info(f"用户名:{username} 密码错误 {failed_login.text_content()}")
|
||||
raise OperationFailed(failed_login.text_content())
|
||||
|
||||
logger.info(f"用户名:{username} 账号密码正确")
|
||||
time.sleep(3)
|
||||
raise OperationFailed("终止任务")
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user