增加账号登录
This commit is contained in:
4
const.py
4
const.py
@@ -24,3 +24,7 @@ BUCKET = 'test'
|
|||||||
# DOVE PROXY
|
# DOVE PROXY
|
||||||
DOVE_USER = 'fetdog'
|
DOVE_USER = 'fetdog'
|
||||||
DOVE_PWD = 'aAa123456aAa'
|
DOVE_PWD = 'aAa123456aAa'
|
||||||
|
|
||||||
|
|
||||||
|
api_key = "adf0d1fc9c9313b7f87c18bf9caef01d"
|
||||||
|
api_url = "http://local.adspower.net:50325"
|
||||||
|
|||||||
3
main.py
3
main.py
@@ -8,7 +8,8 @@ TASK_TYPE = {
|
|||||||
'check_account_cookies': playwright_check_account_cookies,
|
'check_account_cookies': playwright_check_account_cookies,
|
||||||
'comment': playwright_comment,
|
'comment': playwright_comment,
|
||||||
'like': playwright_like,
|
'like': playwright_like,
|
||||||
'post': playwright_post
|
'post': playwright_post,
|
||||||
|
'login_account': playwright_login
|
||||||
}
|
}
|
||||||
|
|
||||||
HOST = "http://192.168.1.69:8001"
|
HOST = "http://192.168.1.69:8001"
|
||||||
|
|||||||
BIN
requirements.txt
BIN
requirements.txt
Binary file not shown.
105
spider/task.py
105
spider/task.py
@@ -7,11 +7,13 @@ import requests
|
|||||||
import threading
|
import threading
|
||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
from const import MIMETYPE, BUCKET, PIC_TYPE, BASE_PATH
|
import pyotp
|
||||||
|
from const import MIMETYPE, BUCKET, PIC_TYPE, BASE_PATH, api_url
|
||||||
from miniofile import client, put_object
|
from miniofile import client, put_object
|
||||||
from exceptions import AuthException, OperationFailed
|
from exceptions import AuthException, OperationFailed
|
||||||
from playwright.sync_api import sync_playwright, Error, TimeoutError
|
from playwright.sync_api import sync_playwright, Error, TimeoutError
|
||||||
from PIL import ImageGrab
|
from PIL import ImageGrab
|
||||||
|
from lxml import html
|
||||||
|
|
||||||
|
|
||||||
# def get_dtsg_token(cookies):
|
# def get_dtsg_token(cookies):
|
||||||
@@ -805,7 +807,7 @@ def check_account_status(page):
|
|||||||
raise AuthException('该账户登录状态失效', 'invalid')
|
raise AuthException('该账户登录状态失效', 'invalid')
|
||||||
except TimeoutError:
|
except TimeoutError:
|
||||||
pass
|
pass
|
||||||
raise AuthException('该账户异常', 'invalid')
|
raise OperationFailed('操作超时或该账户异常,请重试')
|
||||||
|
|
||||||
|
|
||||||
class RLock(threading._RLock):
|
class RLock(threading._RLock):
|
||||||
@@ -901,8 +903,7 @@ def playwright_post(cookies, content, image_key=None):
|
|||||||
if not image_key:
|
if not image_key:
|
||||||
page.click('''//span[contains(text(), "What's on your mind")]''')
|
page.click('''//span[contains(text(), "What's on your mind")]''')
|
||||||
_edit_privacy(page)
|
_edit_privacy(page)
|
||||||
page.type('''//div[contains(@aria-placeholder, "What's on your mind")]''', content)
|
page.type('''//div[contains(@aria-placeholder, "What's on your mind")]''', content, delay=50)
|
||||||
|
|
||||||
page.click('//div[@aria-label="Post"]')
|
page.click('//div[@aria-label="Post"]')
|
||||||
time.sleep(15)
|
time.sleep(15)
|
||||||
post_index = page.locator('//div[@aria-posinset="1"]//a[@role="link"]').nth(2)
|
post_index = page.locator('//div[@aria-posinset="1"]//a[@role="link"]').nth(2)
|
||||||
@@ -980,7 +981,7 @@ def playwright_comment(cookies, target_url, content, image_key=None):
|
|||||||
file_chooser.set_files(file_path)
|
file_chooser.set_files(file_path)
|
||||||
time.sleep(5)
|
time.sleep(5)
|
||||||
|
|
||||||
page.type(input_xpath, content)
|
page.type(input_xpath, content, delay=50)
|
||||||
page.click(comment_xpath)
|
page.click(comment_xpath)
|
||||||
time.sleep(5)
|
time.sleep(5)
|
||||||
except Error as e:
|
except Error as e:
|
||||||
@@ -1123,7 +1124,6 @@ def playwright_check_account_cookies(cookies):
|
|||||||
update_windows_distinguish()
|
update_windows_distinguish()
|
||||||
browser = playwright.chromium.launch(
|
browser = playwright.chromium.launch(
|
||||||
headless=False, args=['--start-maximized'], executable_path=path
|
headless=False, args=['--start-maximized'], executable_path=path
|
||||||
# proxy=dove_proxy.get_playwright_proxy(get_storage(cookies, 'username'))
|
|
||||||
)
|
)
|
||||||
context = browser.new_context(no_viewport=True)
|
context = browser.new_context(no_viewport=True)
|
||||||
context.add_init_script(path=os.path.join(BASE_PATH, 'stealth.min.js'))
|
context.add_init_script(path=os.path.join(BASE_PATH, 'stealth.min.js'))
|
||||||
@@ -1140,20 +1140,85 @@ def playwright_check_account_cookies(cookies):
|
|||||||
return {}
|
return {}
|
||||||
|
|
||||||
|
|
||||||
|
def playwright_login(username, password, code_2fa=None):
|
||||||
|
path = os.path.join(BASE_PATH, 'chrome', '130-0008', 'chrome.exe')
|
||||||
|
with lock:
|
||||||
|
with sync_playwright() as playwright:
|
||||||
|
update_windows_distinguish()
|
||||||
|
browser = playwright.chromium.launch(
|
||||||
|
headless=False, args=['--start-maximized'], executable_path=path,
|
||||||
|
proxy={'server': '127.0.0.1:10889'}
|
||||||
|
)
|
||||||
|
context = browser.new_context(no_viewport=True, user_agent='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/135.0.0.0 Safari/537.36')
|
||||||
|
context.add_init_script(path=os.path.join(BASE_PATH, 'stealth.min.js'))
|
||||||
|
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.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('验证码解析错误')
|
||||||
|
time.sleep(5)
|
||||||
|
auth_span = page.query_selector('//span[text()="Try Another Way"]')
|
||||||
|
if auth_span:
|
||||||
|
if not code_2fa:
|
||||||
|
raise OperationFailed('缺少2FA密钥')
|
||||||
|
auth_code = pyotp.TOTP(code_2fa).now()
|
||||||
|
auth_span.click()
|
||||||
|
page.click('//div[text()="Authentication app"]')
|
||||||
|
page.click('//span[text()="Continue"]')
|
||||||
|
time.sleep(1)
|
||||||
|
page.locator('//label[text()="Code"]/preceding-sibling::input').fill(auth_code)
|
||||||
|
page.click('//span[text()="Continue"]')
|
||||||
|
|
||||||
|
save_profile = page.query_selector('//span[text()="Save"]')
|
||||||
|
if save_profile:
|
||||||
|
save_profile.click()
|
||||||
|
trust_device_select = page.query_selector('''//span[text()="Always confirm that it's me"]''')
|
||||||
|
if trust_device_select:
|
||||||
|
trust_device_select.click()
|
||||||
|
|
||||||
|
time.sleep(10)
|
||||||
|
c = {i['name']: i['value'] for i in context.cookies()}
|
||||||
|
context.close()
|
||||||
|
browser.close()
|
||||||
|
return {'cookies': json.dumps(c)}
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
# cookies = 'sb=mC6pxQuLvNLPTNpF-b9Tk8tK;c_user=61570961343759;xs=18:fBZ4XJkFA69uNg:2:1734940655:-1:-1;fr=0JjwzD0HEedbQSHGt.AWUHNQcfxnkbZ3j5rVd1NgTTGhA.BnaRfv..AAA.0.0.BnaRfv.AWWF3uukqmQ;datr=7xdpZzxiItbht8A5aCDBAhQU'
|
# cookies = 'sb=mC6pxQuLvNLPTNpF-b9Tk8tK;c_user=61570961343759;xs=18:fBZ4XJkFA69uNg:2:1734940655:-1:-1;fr=0JjwzD0HEedbQSHGt.AWUHNQcfxnkbZ3j5rVd1NgTTGhA.BnaRfv..AAA.0.0.BnaRfv.AWWF3uukqmQ;datr=7xdpZzxiItbht8A5aCDBAhQU'
|
||||||
# cookies = 'c_user=61573270029140;xs=13:wxQbtfa7hrujUA:2:1743959715:-1:-1;fr=0iZcgonpqtz82lJCx.AWfaexobO4BF75JHVmDgZDh1i9QyC1NnZb5lozeYLSYVrq5mo6E.Bn8rap..AAA.0.0.Bn8rap.AWeceBbr8N7OEWyajASDe2BKQtw;datr=orbyZzxCYjVtB_NXmCeOc56h'
|
# cookies = 'datr=q13hZowje6bbViFxECQpYyp8; sb=q13hZgJARsRIDmNJG8xUauAe; m_pixel_ratio=1.875; wd=384x686; c_user=61565823476070; fr=01C6Lt4VArm5hELvx.AWXg75HOo-QNJgbiDl8qFtw_5lc.Bm4V2r..AAA.0.0.Bm4V25.AWWHzUeMTuI; xs=50%3A8luhgQ-Ea0vnhg%3A2%3A1726045627%3A-1%3A-1'
|
||||||
cookies = {
|
# cookies = {
|
||||||
'datr': '4MXgZ3twsUMLaR7_yYPjboTs',
|
# 'datr': '4MXgZ3twsUMLaR7_yYPjboTs',
|
||||||
'sb': '4MXgZ5AKdd6AiVqGy_N0-cpe',
|
# 'sb': '4MXgZ5AKdd6AiVqGy_N0-cpe',
|
||||||
'locale': 'zh_CN',
|
# 'locale': 'zh_CN',
|
||||||
'presence': 'C{"t3":[],"utc3":1742784026639,"v":1}',
|
# 'presence': 'C{"t3":[],"utc3":1742784026639,"v":1}',
|
||||||
'ps_n': '1',
|
# 'ps_n': '1',
|
||||||
'wd': '1369x475',
|
# 'wd': '1369x475',
|
||||||
'c_user': '61574433449058',
|
# 'c_user': '61574433449058',
|
||||||
'fr': '04xfKMRdCsbtllhPA.AWUt-rPOi-ist5ZdVHl3jiYcKYM11xLu0MN9gA.Bn4MXg..AAA.0.0.Bn4MYY.AWWmAFxhQek',
|
# 'fr': '04xfKMRdCsbtllhPA.AWUt-rPOi-ist5ZdVHl3jiYcKYM11xLu0MN9gA.Bn4MXg..AAA.0.0.Bn4MYY.AWWmAFxhQek',
|
||||||
'xs': '6:he_0XMG7YzQPKQ:2:1742784022:-1:-1',
|
# 'xs': '6:he_0XMG7YzQPKQ:2:1742784022:-1:-1',
|
||||||
}
|
# }
|
||||||
# post(cookies, 'cs2025')
|
# post(cookies, 'cs2025')
|
||||||
# like(cookies, 'ZmVlZGJhY2s6MTIyMTA5NjE0NjU0NzkzNzc5')
|
# like(cookies, 'ZmVlZGJhY2s6MTIyMTA5NjE0NjU0NzkzNzc5')
|
||||||
# comment(cookies, 'ZmVlZGJhY2s6MTIyMTA5NjE0NjU0NzkzNzc5', 'game la', 'xzpq.mp4')
|
# comment(cookies, 'ZmVlZGJhY2s6MTIyMTA5NjE0NjU0NzkzNzc5', 'game la', 'xzpq.mp4')
|
||||||
@@ -1178,3 +1243,7 @@ if __name__ == '__main__':
|
|||||||
# # image_key='rg.jpg'
|
# # image_key='rg.jpg'
|
||||||
# )
|
# )
|
||||||
# playwright_check_account_cookies(cookies)
|
# playwright_check_account_cookies(cookies)
|
||||||
|
# cookies = playwright_login('61575067907301', '@Badhon@20', 'D54WZQP7VCNDKAKC66Q3WNQYTOFJSAZY')
|
||||||
|
# print(cookies)
|
||||||
|
pass
|
||||||
|
|
||||||
|
|||||||
30
stealth.min.js
vendored
30
stealth.min.js
vendored
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user