Python's itchat library, your little assistant

1. Simple is a few lines of code, just need to install itchat library, the implementation process is as follows:
insert image description here
python third-party library itchat https://github.com/littlecodersh/ItChat

2. Send messages to your friends using 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. Use Python to send messages to the group

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. Use Python to send messages + pictures to the group

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 : send file
@img @path_to_img : send image
@vid@path_to_video : send video

References:

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/

Guess you like

Origin blog.csdn.net/zxxxlh123/article/details/118110098