全网云盘资源分享群

python 微信自动发图片,批量发送

自动发送批量的图片给微信联系人,可为自己的文件传输助手

已实现:

  • 可设置发送时间间隔
  • 发送图片数量
  • 指定接收人

 下载链接:

python批量自动连发图片给微信好友自动发图片-Python文档类资源-CSDN下载

import os
from io import BytesIO
import pyautogui
import pyperclip
import time
import win32clipboard as clip
import win32con
from PIL import Image


def get_img():
    imagepath = "D:/Documents/Pictures/"  # 自己的图片路径
    all = os.walk(imagepath)
    i = 0
    for path, dir, file_list in all:    # 遍历图片
        print(path, dir, file_list)

        for filename in file_list: 
            if filename.endswith('.jpg') or filename.endswith('.png'):
                clip.OpenClipboard()  # 打开剪贴板
                clip.EmptyClipboard()  # 先清空剪贴板
                image = os.path.join(imagepath, path, filename)
                print(image)

                img = Image.open(image)
                output = BytesIO()
                img.convert("RGB").save(output, "BMP")
                data = output.getvalue()[14:]
                output.close()
                clip.SetClipboardData(win32con.CF_DIB, data)  # 将图片放入剪贴板
                clip.CloseClipboard()
                time.sleep(1)
                send()
                i += 1
                if i > 5:  # 想发送 n 张就设置 i > n-1(3 为发送的最大数量-1 i从0开始 所以设置为3,是4张图片:  0 1 2 3)
                    print('发送完成')
                    return 0

 二、发送图片消息

def send():
    # 复制需要发送的内容到粘贴板
    # 模拟键盘 ctrl + v 粘贴内容
    pyautogui.hotkey('ctrl', 'v')
    # 发送消息
    pyautogui.press('enter')

 三、搜索好友

def serch_friend(friend):
    # Ctrl + alt + w 打开微信
    pyautogui.hotkey('ctrl', 'alt', 'w')
    # 搜索好友
    pyautogui.hotkey('ctrl', 'f')
    # 复制好友昵称到粘贴板
    pyperclip.copy(friend)
    # 模拟键盘 ctrl + v 粘贴
    pyautogui.hotkey('ctrl', 'v')
    time.sleep(1)
    # 回车进入好友消息界面
    pyautogui.press('enter')
    get_img()


if __name__ == '__main__':
    friend_name = "好友名或(文件传输助手)"

    serch_friend(friend_name)

 

 

 

 

posted @ 2022-04-04 16:00  颖火虫赵云  阅读(68)  评论(0编辑  收藏  举报  来源
|