Python中的itchat模块使用大全

Posted 刘润森!

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Python中的itchat模块使用大全相关的知识,希望对你有一定的参考价值。

Python中有一个itchat实现微信的分析和登录。

itchat是一个开源的微信个人号接口,使用python调用微信从未如此简单。使用不到三十行的代码,你就可以完成一个能够处理有信息的微信机器人。当然,该api的使用远不止一个机器人,更多的功能等着你来发现。

#实现微信消息的获取

import itchat

@itchat.msg_register(itchat.content.TEXT)
def print_content(msg):
    print(msg[\'Text\'])

itchat.auto_login()
itchat.run()

实现微信消息的发送

import itchat

itchat.auto_login(hotReload=True)

# 注意实验楼环境的中文输入切换
itchat.send(u\'测试消息发送\', \'filehelper\')   

如果接收到TEXT类型的消息,则执行以下的方法,msg是收到的消息,return msg.text是返回收到的消息的内容,实际效果是别人发给你什么,程序自动返回给他什么。

import itchat
from itchat.content import TEXT
@itchat.msg_register
def simple_reply(msg):
  if msg[\'Type\'] == TEXT:
    return \'I received: %s\' % msg[\'Content\']
itchat.auto_login()
itchat.run()

使用itchat统计你的微信好友

以上是关于Python中的itchat模块使用大全的主要内容,如果未能解决你的问题,请参考以下文章

python itchat 用户多开啥意思

itchat用Python玩耍微信

pip安装itchat模块成功后annocanda中No module named 'itchat'

Python 开发个人微信号在运维开发中的使用

python微信自动回复

itchat和matplotlib的结合使用