登录延迟, 有验证码直接抛出错误, 更改登录的语言
This commit is contained in:
@@ -1160,32 +1160,52 @@ def playwright_login(username, password, code_2fa=None):
|
||||
page = context.new_page()
|
||||
url = 'https://www.facebook.com'
|
||||
page.goto(url)
|
||||
page.locator('//input[@id="email"]').type(username, delay=50)
|
||||
page.locator('//input[@id="pass"]').type(password, delay=50)
|
||||
page.locator('//input[@id="email"]').type(username, delay=100)
|
||||
page.locator('//input[@id="pass"]').type(password, delay=100)
|
||||
time.sleep(2)
|
||||
page.click('//button[@name="login"]')
|
||||
time.sleep(5)
|
||||
captcha_img = page.query_selector_all('//img[contains(@src, "captcha")]')
|
||||
if captcha_img:
|
||||
img_file_path = os.path.join(BASE_PATH, 'files', 'captcha.png')
|
||||
captcha_img[0].screenshot(path=img_file_path)
|
||||
with open(img_file_path, 'rb') as f:
|
||||
data = {
|
||||
'user': 'shaowz',
|
||||
'pass2': '69e86586e8a1241719ebacecf7bb84c2',
|
||||
'softid': '951004',
|
||||
'codetype': '3006',
|
||||
}
|
||||
response = requests.post('http://upload.chaojiying.net/Upload/Processing.php',
|
||||
data=data, timeout=60, files={'userfile': f})
|
||||
result = response.json()
|
||||
if result['err_no'] == 0:
|
||||
pic_str = result['pic_str']
|
||||
page.fill('//img[contains(@src, "captcha")]/parent::div/parent::div//input', pic_str)
|
||||
page.locator('//img[contains(@src, "captcha")]/parent::div/parent::div/div').nth(4).click()
|
||||
else:
|
||||
raise OperationFailed('验证码解析错误')
|
||||
# 设置语言为英文
|
||||
context.add_cookies([
|
||||
{
|
||||
"name": "locale",
|
||||
"value": "en_US",
|
||||
"domain": ".facebook.com",
|
||||
"path": "/",
|
||||
"expires": -1,
|
||||
"httpOnly": True,
|
||||
"secure": False,
|
||||
},
|
||||
])
|
||||
page.reload()
|
||||
|
||||
# captcha_img = page.query_selector_all('//img[contains(@src, "captcha")]')
|
||||
# if captcha_img:
|
||||
# img_file_path = os.path.join(BASE_PATH, 'files', 'captcha.png')
|
||||
# captcha_img[0].screenshot(path=img_file_path)
|
||||
# with open(img_file_path, 'rb') as f:
|
||||
# data = {
|
||||
# 'user': 'shaowz',
|
||||
# 'pass2': '69e86586e8a1241719ebacecf7bb84c2',
|
||||
# 'softid': '951004',
|
||||
# 'codetype': '3006',
|
||||
# }
|
||||
# response = requests.post('http://upload.chaojiying.net/Upload/Processing.php',
|
||||
# data=data, timeout=60, files={'userfile': f})
|
||||
# result = response.json()
|
||||
# if result['err_no'] == 0:
|
||||
# pic_str = result['pic_str']
|
||||
# page.fill('//img[contains(@src, "captcha")]/parent::div/parent::div//input', pic_str)
|
||||
# page.locator('//img[contains(@src, "captcha")]/parent::div/parent::div/div').nth(4).click()
|
||||
# else:
|
||||
# raise OperationFailed('验证码解析错误')
|
||||
time.sleep(5)
|
||||
page.wait_for_load_state()
|
||||
h2 = page.query_selector("//h2/span")
|
||||
if h2 is None:
|
||||
raise OperationFailed('页面有误')
|
||||
else:
|
||||
if h2.text_content() != "Check your notifications on another device":
|
||||
raise OperationFailed("操作失败")
|
||||
auth_span = page.query_selector('//span[text()="Try Another Way" or text()="Try another way"]')
|
||||
if auth_span:
|
||||
if not code_2fa:
|
||||
@@ -1253,4 +1273,3 @@ if __name__ == '__main__':
|
||||
# cookies = playwright_login('61575057767684', '@Badhon@20', 'AMULNV6YOAMDGOQ72NNBQCBMTOFB4BTJ')
|
||||
# print(cookies)
|
||||
pass
|
||||
|
||||
|
||||
Reference in New Issue
Block a user