网络编程
位置:首页>> 网络编程>> Python编程>> 基于Python的微信机器人开发 微信登录和获取好友列表实现解析

基于Python的微信机器人开发 微信登录和获取好友列表实现解析

作者:Sch01aR#  发布时间:2021-09-14 17:03:46 

标签:python,微信,机器人,登录,获取,好友,列表

首先需要安装itchat库,可以pip install itchat安装,也可以在pycharm里安装


# -*- coding:utf-8 -*-
__author__ = "MuT6 Sch01aR"
import itchat
def get_friends():
 friends = itchat.get_friends(update=True) #获取微信好友列表,如果设置update=True将从服务器刷新列表
 for i in friends:
   print(i)
def main():
 itchat.auto_login(hotReload=True) #登录,会下载二维码给手机扫描登录,hotReload设置为True表示以后自动登录
 get_friends()
 itchat.run() #让itchat一直运行
if __name__ == "__main__":
 main()

运行结果如下

基于Python的微信机器人开发 微信登录和获取好友列表实现解析

用手机微信扫一下二维码

基于Python的微信机器人开发 微信登录和获取好友列表实现解析

登录成功

获取好友列表的结果

基于Python的微信机器人开发 微信登录和获取好友列表实现解析

来源:https://www.cnblogs.com/sch01ar/p/7827046.html

0
投稿

猜你喜欢

手机版 网络编程 asp之家 www.aspxhome.com