def get_friend_imgs(save_path, get_img_nums=100):
# ????????
if os.path.exists(save_path):
save_path = input(u'????????????????: ')
os.mkdir(save_path)
# ??????
friends = itchat.get_friends()
if get_img_nums > len(friends):
get_img_nums = len(friends)
print(u'?????????????????????? %s' % len(friends))
for num, friend in enumerate(friends):
friend_name = friend['NickName'] or friend['UserName']
# ???????????????
friend_name = re.sub(r'[\s+]', '_', friend_name)
friend_img = itchat.get_head_img(userName=friend['UserName'])
with open(save_path + '/' + friend_name + str(num+1).zfill(3) + '.jpg', 'wb') as f:
print(u'???? %s ???, ???? %s ?' % (friend_name, get_img_nums-num))
f.write(friend_img)
if num > get_img_nums:
print(u'%s ???????' % get_img_nums)
break
评论列表
文章目录