首页 > 解决方案 > 我如何在 Instagram 中查看我的关注者的用户名

问题描述

我想通过 python 在 Instagram 中查看我的关注者列表。我写这段代码

from InstagramAPI import InstagramAPI
username="*******"
InstagramAPI = InstagramAPI(username, "******")
InstagramAPI.login()
InstagramAPI.getProfileData()
followers = InstagramAPI.getTotalSelfFollowers()
print (followers[0])

它工作正常并显示

{u'username': u'yasinyasinyasinl', u'has_anonymous_profile_picture': True, u'profile_pic_url': u'https://instagram.fevn1-1.fna.fbcdn.net/vp/19319123fc5a0016b6fd518cfa7058ce/5D7C0DF1/t51.2885-19/44884218_345707102882519_2446069589734326272_n.jpg?_nc_ht=instagram.fevn1-1.fna.fbcdn.net', u'full_name': u'yasin', u'pk': 5580539929, u'is_verified': False, u'is_private': True}

我想得到我尝试的所有钥匙

for a,b in followers[0]:
  print (followers[0].keys())

但它没有用。我应该怎么办?

print (followers[0].get(username))
None

标签: pythonapiinstagram

解决方案


从你的问题猜测,我认为这followers是一个list元素dict

这意味着这followers[0]将是一个包含您的关注者之一的信息的单个字典。如果要显示该用户名,只需使用followers[0]['username'].

如果您想显示所有关注者,请遍历list

for follower in followers:
  print(follower['username'])

额外提示:知道您可以list使用 Python 的漂亮列表理解轻松获取您的关注者的用户名:[follower['username'] for follower in followers].

希望这有帮助!


推荐阅读