From 2886b1afcbd7bf4382dd3f60b9359c474c10d48d Mon Sep 17 00:00:00 2001 From: work Date: Fri, 25 Apr 2025 15:21:31 +0800 Subject: [PATCH] =?UTF-8?q?=E7=99=BB=E5=BD=95=E5=BB=B6=E8=BF=9F,=20?= =?UTF-8?q?=E6=9C=89=E9=AA=8C=E8=AF=81=E7=A0=81=E7=9B=B4=E6=8E=A5=E6=8A=9B?= =?UTF-8?q?=E5=87=BA=E9=94=99=E8=AF=AF,=20=E6=9B=B4=E6=94=B9=E7=99=BB?= =?UTF-8?q?=E5=BD=95=E7=9A=84=E8=AF=AD=E8=A8=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- spider/task.py | 67 ++++++++++++++++++++++++++++++++------------------ 1 file changed, 43 insertions(+), 24 deletions(-) diff --git a/spider/task.py b/spider/task.py index c505008..e212822 100644 --- a/spider/task.py +++ b/spider/task.py @@ -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 -