移动端登录问题修复
This commit is contained in:
7
const.py
7
const.py
@@ -21,9 +21,10 @@ ACCESS_KEY = '3QcjsqdCYCoy1khuDqia'
|
|||||||
SECRET_KEY = 'iPXte32y1deoySiDq0RwONUJIiIgvjTVhbfCL8tV'
|
SECRET_KEY = 'iPXte32y1deoySiDq0RwONUJIiIgvjTVhbfCL8tV'
|
||||||
BUCKET = 'facebook'
|
BUCKET = 'facebook'
|
||||||
|
|
||||||
# DOVE PROXY
|
# PROXY
|
||||||
DOVE_USER = 'fetdog'
|
PROXY_HOST = 'http://proxy.ipipgo.com:31212'
|
||||||
DOVE_PWD = 'aAa123456aAa'
|
PROXY_USER = 'customer-94620c-country-US'
|
||||||
|
PROXY_PASS = '4ea715cd'
|
||||||
|
|
||||||
|
|
||||||
api_key = "adf0d1fc9c9313b7f87c18bf9caef01d"
|
api_key = "adf0d1fc9c9313b7f87c18bf9caef01d"
|
||||||
|
|||||||
@@ -1364,67 +1364,56 @@ def playwright_m_login(username, password, code_2fa=None):
|
|||||||
page = context.new_page()
|
page = context.new_page()
|
||||||
url = 'https://m.facebook.com/login'
|
url = 'https://m.facebook.com/login'
|
||||||
retry_goto(page, url)
|
retry_goto(page, url)
|
||||||
|
|
||||||
|
page.wait_for_load_state('networkidle')
|
||||||
# 概率会跳到首页
|
# 概率会跳到首页
|
||||||
have_account = 'div[role="button"][aria-label="I already have an account"]'
|
have_account = 'div[role="button"][aria-label="I already have an account"]'
|
||||||
# 用户名输入框框
|
|
||||||
input_email = "input#m_login_email"
|
|
||||||
|
|
||||||
try:
|
|
||||||
page.wait_for_selector(f'{have_account}, {input_email}', timeout=60000)
|
|
||||||
except Exception as e:
|
|
||||||
logger.error(f"页面加载异常, 未定位到按钮", exc_info=True)
|
|
||||||
raise OperationFailed("系统异常")
|
|
||||||
|
|
||||||
hava_account_btn = page.query_selector(have_account)
|
hava_account_btn = page.query_selector(have_account)
|
||||||
if hava_account_btn:
|
if hava_account_btn:
|
||||||
hava_account_btn.click()
|
hava_account_btn.click()
|
||||||
|
|
||||||
page.wait_for_selector(f'{input_email}', timeout=60000).type(username, delay=30)
|
page.wait_for_selector('//input[@id="m_login_email"]', timeout=60000).type(username, delay=30)
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
page.wait_for_selector(f'//input[@id="m_login_password"]', timeout=60000).type(password, delay=30)
|
page.wait_for_selector(f'//input[@id="m_login_password"]', timeout=60000).type(password, delay=30)
|
||||||
time.sleep(1)
|
|
||||||
page.click('div[aria-label="Log in"]')
|
page.click('div[aria-label="Log in"]')
|
||||||
|
page.wait_for_selector('//div[@aria-label="Loading..."]', state='detached')
|
||||||
|
|
||||||
success_login_selector1 = 'span:has-text("Check your notifications on another device")'
|
time.sleep(5)
|
||||||
success_login_selector2 = 'span:has-text("Go to your authentication app")'
|
login_wrong = page.query_selector('//div[@aria-label="Wrong Credentials"]')
|
||||||
failed_login_selector = 'div[data-bloks-name="bk.components.dialog.Dialog"] > div[aria-label="Wrong Credentials"] > div:nth-child(1)'
|
if login_wrong:
|
||||||
# 等成功或失败两个选择的其中一个
|
# 账号密码错误报错
|
||||||
page.wait_for_selector(f'{success_login_selector1},{success_login_selector2}, {failed_login_selector}',
|
wrong_text = page.locator('//div[@aria-label="Wrong Credentials"]/div/div[2]').first.inner_text()
|
||||||
timeout=60000)
|
raise AuthException(wrong_text)
|
||||||
|
|
||||||
# 判断是否失败
|
# 身份验证
|
||||||
failed_login = page.query_selector(failed_login_selector)
|
auth_span = page.query_selector('//span[text()="Try Another Way" or text()="Try another way"]')
|
||||||
if failed_login:
|
if auth_span:
|
||||||
# 登录失败, 返回失败信息
|
if not code_2fa:
|
||||||
logger.info(f"用户名:{username} 密码错误 {failed_login.text_content()}")
|
raise OperationFailed('缺少2FA密钥')
|
||||||
raise OperationFailed(failed_login.text_content())
|
auth_code = pyotp.TOTP(code_2fa).now()
|
||||||
|
auth_span.click()
|
||||||
|
page.wait_for_selector('//span[text()="Authentication app"]').click()
|
||||||
|
page.locator('//span[text()="Continue"]').first.click()
|
||||||
|
page.wait_for_selector('//input[@aria-label="Code"]').fill(auth_code)
|
||||||
|
page.locator('//span[text()="Continue"]').first.click()
|
||||||
|
page.wait_for_selector('//div[@data-visualcompletion="loading-state"]', state='detached')
|
||||||
|
time.sleep(5)
|
||||||
|
auth_wrong = page.query_selector('//span[text()="This code doesn’t work. Check it’s correct or try a new one."]')
|
||||||
|
if auth_wrong:
|
||||||
|
raise AuthException('f2a代码错误')
|
||||||
|
|
||||||
# 判断是否有多重验证
|
# 保存登录
|
||||||
success_login1 = page.query_selector(success_login_selector1)
|
save_span = page.query_selector('//span[text()="Save"]')
|
||||||
if success_login1:
|
if save_span:
|
||||||
# 点击尝试另一种方式验证账号
|
save_span.click()
|
||||||
page.query_selector('div[role="button"][aria-label="Try another way"]').click()
|
page.wait_for_selector('//div[@data-visualcompletion="loading-state"]', state='detached')
|
||||||
|
|
||||||
# 点击选择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.wait_for_selector('span:has-text("Go to your authentication app")', timeout=60000)
|
|
||||||
|
|
||||||
# 输入2faCode
|
|
||||||
auth_code = pyotp.TOTP(code_2fa).now()
|
|
||||||
page.wait_for_selector('input[aria-label="Code"][type="text"]', timeout=60000).fill(auth_code)
|
|
||||||
|
|
||||||
# 点击继续
|
|
||||||
page.query_selector('div[role="button"][aria-label="Continue"]').click()
|
|
||||||
|
|
||||||
# 等待登录成功
|
|
||||||
page.wait_for_selector('img[data-bloks-name="bk.components.Image"][src*=".fbcdn.net/v/t"]',timeout=60000)
|
|
||||||
|
|
||||||
|
# 等待页面加载
|
||||||
|
page.wait_for_load_state()
|
||||||
|
try:
|
||||||
|
page.wait_for_selector('//div[@role="tab"]', timeout=60000)
|
||||||
|
except TimeoutError:
|
||||||
|
pass
|
||||||
# 成功
|
# 成功
|
||||||
logger.info(f"用户名:{username} 账号密码正确")
|
logger.info(f"用户名:{username} 账号密码正确")
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user