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