Python的itchat库,你的小助手

1.简单是几行代码,只需要安装itchat这个库,实现过程如下:
在这里插入图片描述
python第三方库itchat https://github.com/littlecodersh/ItChat

2.使用Python发送消息给你的朋友

import itchat
itchat.auto_login(hotReload=True)
print('扫描二维码')
remark_name = input('输入收信息人的备注:')
information = input('输入发送的内容:')
boom_ = itchat.search_friends(remarkName=remark_name)[0]['UserName']#指定人
for i in range(3):
    itchat.send_msg(information,toUserName=boom_)

3.使用Python给群发送消息

import itchat
itchat.auto_login(enableCmdQR=True)#另外一种载入二维码的方式
room_name = input('输入接收信息的群名:')
information = input('输入要发送的内容:')
#rooms=itchat.get_chatrooms(update=True) #拿到所有群
rooms_=itchat.search_chatrooms(name=room_name)[0]['UserName'] #指定群
for i in range(3):
    itchat.send(information,toUserName=rooms_)

4.使用Python给群发送消息+图片

print('扫一下二维码')
itchat.auto_login(enableCmdQR=True)
room_name = input('输入接收信息的群名称:')
rooms=itchat.get_chatrooms(update=True) #拿到所有群
rooms_=itchat.search_chatrooms(name=room_name)[0]['UserName'] #搜索指定群
itchat.send('第二节课的思维导图想要么?',toUserName=rooms_)
itchat.send("@img@%s" % 'mindmap.png',toUserName=rooms_)

@fil@path_to_file : 发送文件
@img@path_to_img : 发送图片
@vid@path_to_video : 发送视频

参考资料:

1.https://www.bilibili.com/read/cv11064085
2.https://blog.csdn.net/qq_41597912/article/details/82719217
3.https://zhuanlan.zhihu.com/p/33970981
4.https://zhuanlan.zhihu.com/p/64139965
5.https://itchat.readthedocs.io/zh/latest/

猜你喜欢

转载自blog.csdn.net/zxxxlh123/article/details/118110098
今日推荐