200字范文,内容丰富有趣,生活中的好帮手!
200字范文 > python 使用wxpy实现获取微信好友列表 头像 群成员

python 使用wxpy实现获取微信好友列表 头像 群成员

时间:2023-08-20 13:08:57

相关推荐

python 使用wxpy实现获取微信好友列表 头像 群成员

最近在学习 python 突然想要试试能不能把微信里面的微信群和好友取出来 结果百度了一下 找到了 wxpy 这怎么能不试一下呢

用到 wxpy、threading、os、time 四个库

第一步 判断文件夹是否存在 不存在则创建

if not os.path.exists('./info/' + wechat.myself.name):filepath = os.getcwd()os.makedirs(filepath + '/info/' + wechat.myself.name + '/headImg')self.getFriendsList()

第二步 先初始化 并获取当前登录人和好友信息

self.bot = Bot()self.myself = self.bot.selfself.friends = self.bot.friends()

第三步 循环好友列表并获取好友信息、下载头像

for i in range(len(self.friends)):if i == 0:writeType = 'w'else:writeType = 'a't = threading.Thread(target=self.writeWechatInfo, args=(self.friends[i], writeType, 'f',))t1 = threading.Thread(target=self.saveHeadImg, args=(self.friends[i],))t.start()t1.start()

第四步 获取所有群 并遍历 获取到群成员后 保存昵称 并退出登录

groups = self.bot.groups()for i in range(len(groups)):group = groups[i]for f in range(len(group.members)):if f == 0:writeType = 'w'else:writeType = 'a't = threading.Thread(target=self.writeWechatInfo, args=(group.members[f], writeType, group.name,))t.start()self.bot.logout()

写完这四大步基本上就可以获取到你的好友列表 和群友列表啦啦

代码地址

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。