import pyautogui
import time
import random
def like_video():
# 模拟点击点赞按钮
# 注意:点赞按钮的位置需要根据屏幕分辨率和抖音界面进行调整
# 使用截图工具获取点赞按钮的位置
like_button_position = pyautogui.locateOnScreen(‘like_button.png’, confidence=0.8)
if like_button_position:
pyautogui.click(like_button_position)
print(“点赞成功”)
else:
print(“未找到点赞按钮”)
def comment_video(comment):
# 模拟点击评论框
# 使用截图工具获取评论框的位置
comment_box_position = pyautogui.locateOnScreen(‘comment_box.png’, confidence=0.8)
if comment_box_position:
pyautogui.click(comment_box_position)
time.sleep(1)
pyautogui.write(comment)
time.sleep(1)
pyautogui.press(‘enter’)
print(“评论成功”)
else:
print(“未找到评论框”)
def automate_douyin(comment_text):
for _ in range(5): # 假设对5个视频进行点赞和评论
try:
# 添加随机延迟避免被检测为机器人
time.sleep(random.uniform(1, 3))
like_video()
time.sleep(random.uniform(1, 3))
comment_video(comment_text)
time.sleep(random.uniform(1, 3))
# 模拟滚动到下一个视频
pyautogui.scroll(-100) # 向下滚动
time.sleep(2)
except Exception as e:
print(f"操作失败: {e}")
if name == “main”:
comment_text = “这是一个自动评论的示例!”
automate_douyin(comment_text)
print(“自动点赞和评论完成!”)