现提供一种轻量化的微信发送消息的代码:
import pyautogui
import pyperclip
import time
def get_msg():
"""想发的消息,每条消息空格分开"""
contents = [i.strip() for i in open('你要发送的文档(按行发送)', 'r', encoding='utf-8').readlines() if i != '\n']
# story.txt是你要给她讲的故事
return contents
def send(msg):
# 复制需要发送的内容到粘贴板
pyperclip.copy(msg)
# 模拟键盘 ctrl + v 粘贴内容
pyautogui.hotkey('ctrl', 'v')
# 发送消息
pyautogui.press('enter')
def send_msg(friend):
# Ctrl + alt + w 打开微信
# while 1:
pyautogui.hotkey('ctrl', 'alt', 'w')
# 搜索好友
pyautogui.hotkey('ctrl', 'f')
# 复制好友昵称到粘贴板你好
pyperclip.copy(friend)
# 模拟键盘 ctrl + v 粘贴
pyautogui.hotkey('ctrl', 'v')
time.sleep(1)
# 回车进入好友消息界面
pyautogui.press('enter')
# 一条一条发送消息
for msg in get_msg():
send(msg)
# 每条消息间隔 2 秒
time.sleep(2)
if __name__ == '__main__':
friend_name = "文件传输助手"#这里写你给对方的备注
send_msg(friend_name)
有其他需求可以联系我。