支持截图,文件存储改用minio
This commit is contained in:
9
const.py
9
const.py
@@ -16,11 +16,10 @@ ELEMENT = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
# ucloud-us3
|
# ucloud-us3
|
||||||
PUBLIC_KEY = '4ZF9nrEbA93FDL29606cKFGYEb59Zu9ip' # 账户公钥
|
ENDPOINT = "154.19.186.49"
|
||||||
PRIVATE_KEY = 'FD9DgHZVe4Q9GevRb8QcwBD6S8Iesv48ZBsWImwEGPZr' # 账户私钥
|
ACCESS_KEY = '3QcjsqdCYCoy1khuDqia'
|
||||||
BUCKET = 'fanzhixitong' # 空间名称
|
SECRET_KEY = 'iPXte32y1deoySiDq0RwONUJIiIgvjTVhbfCL8tV'
|
||||||
UPLOAD_SUFFIX = '.jpn-tky.ufileos.com'
|
BUCKET = 'facebook'
|
||||||
DOWNLOAD_SUFFIX = '.jpn-tky.ufileos.com'
|
|
||||||
|
|
||||||
# DOVE PROXY
|
# DOVE PROXY
|
||||||
DOVE_USER = 'fetdog'
|
DOVE_USER = 'fetdog'
|
||||||
|
|||||||
16
miniofile.py
Normal file
16
miniofile.py
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
from const import ENDPOINT, ACCESS_KEY, SECRET_KEY, BUCKET
|
||||||
|
from minio import Minio
|
||||||
|
|
||||||
|
client = Minio(
|
||||||
|
endpoint=ENDPOINT,
|
||||||
|
access_key=ACCESS_KEY,
|
||||||
|
secret_key=SECRET_KEY,
|
||||||
|
secure=False
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def put_object(name, content):
|
||||||
|
length = len(content.getbuffer())
|
||||||
|
content.seek(0)
|
||||||
|
client.put_object(BUCKET, name, content, length)
|
||||||
|
|
||||||
BIN
requirements.txt
BIN
requirements.txt
Binary file not shown.
@@ -10,10 +10,11 @@ import threading
|
|||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
from const import MIMETYPE, BUCKET, PIC_TYPE, BASE_PATH
|
from const import MIMETYPE, BUCKET, PIC_TYPE, BASE_PATH
|
||||||
from uclouds3 import client
|
from miniofile import client, put_object
|
||||||
from urllib.parse import quote
|
from urllib.parse import quote
|
||||||
from exceptions import AuthException, OperationFailed
|
from exceptions import AuthException, OperationFailed
|
||||||
from playwright.sync_api import sync_playwright
|
from playwright.sync_api import sync_playwright
|
||||||
|
from PIL import ImageGrab
|
||||||
|
|
||||||
|
|
||||||
def get_dtsg_token(cookies):
|
def get_dtsg_token(cookies):
|
||||||
@@ -707,6 +708,14 @@ def sleep(a, b):
|
|||||||
return time.sleep(round(random.uniform(a, b), 1))
|
return time.sleep(round(random.uniform(a, b), 1))
|
||||||
|
|
||||||
|
|
||||||
|
def _full_screenshot():
|
||||||
|
im = ImageGrab.grab()
|
||||||
|
mem_file = io.BytesIO()
|
||||||
|
# 保存到内存中
|
||||||
|
im.save(mem_file, "png")
|
||||||
|
return mem_file
|
||||||
|
|
||||||
|
|
||||||
def update_windows_distinguish(x=1920, y=1080):
|
def update_windows_distinguish(x=1920, y=1080):
|
||||||
"""更改windows分辨率"""
|
"""更改windows分辨率"""
|
||||||
if sys.platform == "win32":
|
if sys.platform == "win32":
|
||||||
@@ -791,8 +800,12 @@ def playwright_like(cookies, post_id):
|
|||||||
page.click(button_xpath)
|
page.click(button_xpath)
|
||||||
time.sleep(10)
|
time.sleep(10)
|
||||||
|
|
||||||
|
content = _full_screenshot()
|
||||||
context.close()
|
context.close()
|
||||||
browser.close()
|
browser.close()
|
||||||
|
key = f'{uuid.uuid4()}.png'
|
||||||
|
put_object(key, content)
|
||||||
|
return {'image_key': key}
|
||||||
|
|
||||||
|
|
||||||
def playwright_post(cookies, message, image_key=None):
|
def playwright_post(cookies, message, image_key=None):
|
||||||
@@ -818,7 +831,7 @@ def playwright_post(cookies, message, image_key=None):
|
|||||||
if image_key:
|
if image_key:
|
||||||
filename = image_key.split('/')[-1]
|
filename = image_key.split('/')[-1]
|
||||||
file_path = os.path.join(BASE_PATH, 'files', filename)
|
file_path = os.path.join(BASE_PATH, 'files', filename)
|
||||||
client.download_file(BUCKET, image_key, file_path)
|
client.fget_object(BUCKET, image_key, file_path)
|
||||||
page.click('//span[text()="Photo/video"]')
|
page.click('//span[text()="Photo/video"]')
|
||||||
sleep(1, 2)
|
sleep(1, 2)
|
||||||
with page.expect_file_chooser() as fc_info:
|
with page.expect_file_chooser() as fc_info:
|
||||||
@@ -838,9 +851,17 @@ def playwright_post(cookies, message, image_key=None):
|
|||||||
post_url = page.locator('//div[@data-pagelet="FeedUnit_0"]//a[@role="link"]').nth(2).get_attribute('href')
|
post_url = page.locator('//div[@data-pagelet="FeedUnit_0"]//a[@role="link"]').nth(2).get_attribute('href')
|
||||||
if '&__cft__' in post_url:
|
if '&__cft__' in post_url:
|
||||||
post_url = post_url.split('&__cft__')[0]
|
post_url = post_url.split('&__cft__')[0]
|
||||||
|
page.goto(post_url)
|
||||||
|
time.sleep(5)
|
||||||
|
content = _full_screenshot()
|
||||||
|
if image_key:
|
||||||
|
os.remove(file_path)
|
||||||
context.close()
|
context.close()
|
||||||
browser.close()
|
browser.close()
|
||||||
return {'resp_id': post_url}
|
|
||||||
|
key = f'{uuid.uuid4()}.png'
|
||||||
|
put_object(key, content)
|
||||||
|
return {'resp_id': post_url, 'image_key': key}
|
||||||
|
|
||||||
|
|
||||||
def playwright_comment(cookies, post_id, message, image_key=None):
|
def playwright_comment(cookies, post_id, message, image_key=None):
|
||||||
@@ -891,7 +912,7 @@ def playwright_comment(cookies, post_id, message, image_key=None):
|
|||||||
if image_key:
|
if image_key:
|
||||||
filename = image_key.split('/')[-1]
|
filename = image_key.split('/')[-1]
|
||||||
file_path = os.path.join(BASE_PATH, 'files', filename)
|
file_path = os.path.join(BASE_PATH, 'files', filename)
|
||||||
client.download_file(BUCKET, image_key, file_path)
|
client.fget_object(BUCKET, image_key, file_path)
|
||||||
sleep(1, 2)
|
sleep(1, 2)
|
||||||
with page.expect_file_chooser() as fc_info:
|
with page.expect_file_chooser() as fc_info:
|
||||||
page.click(attach_xpath)
|
page.click(attach_xpath)
|
||||||
@@ -901,10 +922,17 @@ def playwright_comment(cookies, post_id, message, image_key=None):
|
|||||||
|
|
||||||
page.type(input_xpath, message)
|
page.type(input_xpath, message)
|
||||||
page.click(comment_xpath)
|
page.click(comment_xpath)
|
||||||
|
time.sleep(5)
|
||||||
|
content = _full_screenshot()
|
||||||
|
if image_key:
|
||||||
|
os.remove(file_path)
|
||||||
context.close()
|
context.close()
|
||||||
browser.close()
|
browser.close()
|
||||||
|
|
||||||
|
key = f'{uuid.uuid4()}.png'
|
||||||
|
put_object(key, content)
|
||||||
|
return {'image_key': key}
|
||||||
|
|
||||||
|
|
||||||
def playwright_get_user_profile(cookies):
|
def playwright_get_user_profile(cookies):
|
||||||
path = os.path.join(BASE_PATH, 'chrome', '130-0008', 'chrome.exe')
|
path = os.path.join(BASE_PATH, 'chrome', '130-0008', 'chrome.exe')
|
||||||
@@ -933,10 +961,14 @@ def playwright_get_user_profile(cookies):
|
|||||||
response = requests.get(
|
response = requests.get(
|
||||||
url=profile_pic_url,
|
url=profile_pic_url,
|
||||||
headers={'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36'},
|
headers={'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36'},
|
||||||
|
# proxies={
|
||||||
|
# 'http': 'http://127.0.0.1:10889',
|
||||||
|
# 'https': 'http://127.0.0.1:10889',
|
||||||
|
# }
|
||||||
)
|
)
|
||||||
bio = io.BytesIO(response.content)
|
bio = io.BytesIO(response.content)
|
||||||
key = f"facebook/{nickname.replace(' ', '_')}.png"
|
key = f"{nickname.replace(' ', '_')}.png"
|
||||||
client.putstream(BUCKET, key, bio)
|
put_object(key, bio)
|
||||||
return {'profile_pic': key, 'nickname': nickname}
|
return {'profile_pic': key, 'nickname': nickname}
|
||||||
|
|
||||||
|
|
||||||
@@ -982,7 +1014,7 @@ def playwright_set_user_profile(cookies, firstname=None, lastname=None, image_ke
|
|||||||
page.click('//a[@aria-label="Profile picture"]')
|
page.click('//a[@aria-label="Profile picture"]')
|
||||||
filename = image_key.split('/')[-1]
|
filename = image_key.split('/')[-1]
|
||||||
file_path = os.path.join(BASE_PATH, 'files', filename)
|
file_path = os.path.join(BASE_PATH, 'files', filename)
|
||||||
client.download_file(BUCKET, image_key, file_path)
|
client.fget_object(BUCKET, image_key, file_path)
|
||||||
sleep(1, 2)
|
sleep(1, 2)
|
||||||
with page.expect_file_chooser() as fc_info:
|
with page.expect_file_chooser() as fc_info:
|
||||||
page.click('//div[text()="Upload new photo"]')
|
page.click('//div[text()="Upload new photo"]')
|
||||||
@@ -990,6 +1022,7 @@ def playwright_set_user_profile(cookies, firstname=None, lastname=None, image_ke
|
|||||||
file_chooser.set_files(file_path)
|
file_chooser.set_files(file_path)
|
||||||
page.locator('//span[text()="Save"]').last.click()
|
page.locator('//span[text()="Save"]').last.click()
|
||||||
time.sleep(5)
|
time.sleep(5)
|
||||||
|
os.remove(file_path)
|
||||||
|
|
||||||
context.close()
|
context.close()
|
||||||
browser.close()
|
browser.close()
|
||||||
@@ -1042,23 +1075,24 @@ if __name__ == '__main__':
|
|||||||
# playwright_test(cookies)
|
# playwright_test(cookies)
|
||||||
# post(cookies, 'cs2025')
|
# post(cookies, 'cs2025')
|
||||||
# like(cookies, 'ZmVlZGJhY2s6MTIyMTA5NjE0NjU0NzkzNzc5')
|
# like(cookies, 'ZmVlZGJhY2s6MTIyMTA5NjE0NjU0NzkzNzc5')
|
||||||
# comment(cookies, 'ZmVlZGJhY2s6MTIyMTA5NjE0NjU0NzkzNzc5', 'game la', 'facebook/xzpq.mp4')
|
# comment(cookies, 'ZmVlZGJhY2s6MTIyMTA5NjE0NjU0NzkzNzc5', 'game la', 'xzpq.mp4')
|
||||||
# playwright_like(cookies, 'https://www.facebook.com/watch/?v=1007800324567828')
|
# playwright_like(cookies, 'https://www.facebook.com/watch/?v=1007800324567828')
|
||||||
# print(playwright_post(cookies, '2025-3-230~like'))
|
# print(playwright_post(cookies, '2025-3-230~like'))
|
||||||
# playwright_post(cookies, '2025-3-26~like', 'face/rg.jpg')
|
# playwright_post(cookies, '2025-3-26~like', 'rg.jpg')
|
||||||
# playwright_comment(
|
# playwright_comment(
|
||||||
# cookies,
|
# cookies,
|
||||||
|
# 'https://www.facebook.com/permalink.php?story_fbid=122096663738814448&id=61574433449058',
|
||||||
# # 'https://www.facebook.com/watch/?v=1603348023628396',
|
# # 'https://www.facebook.com/watch/?v=1603348023628396',
|
||||||
# # 'https://www.facebook.com/permalink.php?story_fbid=635052906055594&id=100086526695858',
|
# # 'https://www.facebook.com/permalink.php?story_fbid=635052906055594&id=100086526695858',
|
||||||
# 'https://www.facebook.com/reel/3578555425778137',
|
# # 'https://www.facebook.com/reel/3578555425778137',
|
||||||
# '2025-3-26~like',
|
# '2025-3-26~like',
|
||||||
# # 'face/rg.jpg'
|
# # 'rg.jpg'
|
||||||
# )
|
# )
|
||||||
# print(playwright_get_user_profile(cookies))
|
# print(playwright_get_user_profile(cookies))
|
||||||
# playwright_set_user_profile(
|
# playwright_set_user_profile(
|
||||||
# cookies,
|
# cookies,
|
||||||
# firstname='Lisa',
|
# firstname='Lisa',
|
||||||
# lastname='Keals',
|
# lastname='Keals',
|
||||||
# image_key='facebook/rg.jpg'
|
# image_key='rg.jpg'
|
||||||
# )
|
# )
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user