Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How does Python make Wechat Robot

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

In this issue, Xiaobian will bring you about how Python makes WeChat robots. The article is rich in content and analyzes and narrates from a professional perspective. After reading this article, I hope you can gain something.

I. Environmental configuration

Most people can't log in to the web version, so bypass it to simulate computer login, and remember to install this module:

pip install itchat-uosip install itchat II. Login #code to log in to personal WeChat account import itchatitchat.auto_login(hotReload=True)#hotReload= True You can temporarily store the login status. After exiting, restart within a certain time without scanning the code again. Third, the first simple message sent monitoring

For example, send a message to the file transfer assistant and monitor it in real time. Code:

# coding=gbk"" Author: Chuan Chuan @ Time: 2021/12/24 15:59""import itchatimport time@itchat.msg_register(itchat.content.TEXT)def reply_msg(msg): print("Received a message: ",msg.text)if __name__== '__main__': itchat.auto_login() time.sleep(5) itchat.send("Hello, little helper", toUserName="filehelper") itchat.run()

The effects are as follows:

IV. Specify a WeChat friend to send a message

For example, to automatically send a message to Zhang San, the code is as follows:

#Code login personal WeChat account import itchatitchat.auto_login(hotReload=True)#hotReload= True You can temporarily store the login status, and restart it within a certain period of time after exiting without scanning the code again.# itchat.auto_login(hotReload=True)friends_list =itchat.get_friends(update=True)users =itchat.search_friends(name=u'Zhang San') userName = users[0]["UserName"]itchat.send ('Testing WeChat bots... ' ,toUserName = userName)

Effect:

V. Monitoring of all WeChat groups

The effect is as follows: (individual remarks I mosaic)

Test results:

VI. Public number monitoring

Effect:

This is to monitor all public accounts, designated to my own public account: Chuan Chuan rookie sends messages

VII. Send messages regularly

For example, remember to remind a big lazy bug to eat every day, and execute it at twelve o 'clock every day:

# coding=gbk"" Author: Chuan Chuan @ Time: 2021/12/24 16:26 Group: 970353786""import itchatfrom apscheduler.schedulers.blocking import BlockingScheduler#Send message def send_msg(): user_info = itchat.search_friends(name='Little Bell') if len(user_info) > 0: user_name = user_info[0]['UserName'] itchat.send_msg ('Remember to eat, lazy worm! ', toUserName=user_name)def after_login(): #The current mission will be executed at twelve o'clock every day of the month sched.add_job(send_msg, 'cron', month='*', day='*', hour='12') sched.start()def after_logout(): sched.shutdown()if __name__ == '__main__': sched = BlockingScheduler() itchat.auto_login(loginCallback=after_login, exitCallback=after_login,hotReload=True) itchat.run()

No, the code is correct.

VIII. WeChat intelligent chat robot

The effect is:

The above is how Python shared by Xiaobian for everyone makes WeChat robots. If there are similar doubts, please refer to the above analysis for understanding. If you want to know more about it, please pay attention to the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report