网站制作公司 郑州,wordpress图片中文不显示解决,成都住建局官网查询,wordpress表格代码自从微信禁止网页版登陆之后#xff0c;itchat 库实现的功能也就都不能用了#xff0c;那现在 Python 还能操作微信吗#xff1f;答案是还可以。目前有一个项目 WechatPCAPI 可以对微信进行操作#xff0c;简单来说它是直接操作 PC 版微信客户端的#xff0c;当然它有一…自从微信禁止网页版登陆之后itchat 库实现的功能也就都不能用了那现在 Python 还能操作微信吗答案是还可以。目前有一个项目 WechatPCAPI 可以对微信进行操作简单来说它是直接操作 PC 版微信客户端的当然它有一定不足之处就是PC 版微信客户端和 Python 都需要使用指定版本的本文我们使用的 Python 版本为 3.7.6 微信客户端使用版本为 2.6.8.52 WechatPCAPI 的 GitHub 地址为 https://github.com/Mocha-L/WechatPCAPI 。获取好友列表WechatPCAPI 提供了方法 get_friends() 该方法返回信息包括好友、群和公众号的列表信息信息内容主要包括微信号、昵称和自己设置的备注。我们使用获取的昵称做个简单的词云展示代码实现如下所示logging.basicConfig(levellogging.INFO)def on_message(message):passdef get_friends():# 初始化微信实例wx_inst WechatPCAPI(on_messageon_message, loglogging)# 启动微信wx_inst.start_wechat(blockTrue)# 等待登陆成功此时需要人为扫码登录微信while not wx_inst.get_myself():time.sleep(5)print(登陆成功)nicknames []# 排除的词remove [还是, 不会, 一些, 所以, 果然,起来, 东西, 为什么, 真的, 这么,但是, 怎么, 还是, 时候, 一个,什么, 自己, 一切, 样子, 一样,没有, 不是, 一种, 这个, 为了]for key, value in wx_inst.get_friends().items():if key in [fmessage, floatbottle, filehelper] or chatroom in key:continuenicknames.append(value[wx_nickname])words []for text in nicknames:if not text:continuefor t in jieba.cut(text):if t in remove:continuewords.append(t)global word_cloud# 用逗号隔开词语word_cloud .join(words)def nk_cloud():# 打开词云背景图cloud_mask np.array(Image.open(bg.png))# 定义词云的一些属性wc WordCloud(# 背景图分割颜色为白色background_colorwhite,# 背景图样maskcloud_mask,# 显示最大词数max_words300,# 显示中文font_path./fonts/simkai.ttf,# 最大尺寸max_font_size70)global word_cloud# 词云函数x wc.generate(word_cloud)# 生成词云图片image x.to_image()# 展示词云图片image.show()# 保存词云图片wc.to_file(nk.png)看一下效果消息防撤回我们在使用微信和好友聊天时对方有时会有撤回消息的情况正常情况下我们是不知道好友撤回的消息是什么的通过 WechatPCAPI 就可以实现消息防撤回的功能。我们知道通常撤回的消息是点击撤回操作前一步发送的内容当然也可能撤回的是前两步、三步 ... 的消息这里我们只对撤回前一步的消息做处理基本思路是我们将撤回前一步发送的消息存一下当对方点击撤回操作时我们再将前一步的消息再次返回给自己。下面看一下实现代码logging.basicConfig(levellogging.INFO)queue_recved_event Queue()def on_message(msg):queue_recved_event.put(msg)def login():pre_msg # 初始化微信实例wx_inst WechatPCAPI(on_messageon_message, loglogging)# 启动微信wx_inst.start_wechat(blockTrue)# 等待登陆成功此时需要人为扫码登录微信while not wx_inst.get_myself():time.sleep(5)print(登陆成功)while True:msg queue_recved_event.get()data msg.get(data)sendinfo data.get(sendinfo)data_type str(data.get(data_type))msgcontent str(data.get(msgcontent))is_recv data.get(is_recv)print(msg)if data_type 1 and revokemsg not in msgcontent:pre_msg msgcontentif sendinfo is not None and revokemsg in msgcontent:user str(sendinfo.get(wx_id_search))recall 撤回的消息 pre_msgwx_inst.send_text(to_useruser, msgrecall)看一下操作效果