【问题标题】:How can i see the username of my followers in instagram我如何在 Instagram 中查看我的关注者的用户名
【发布时间】:2019-05-26 17:52:34
【问题描述】:

我想通过 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

【问题讨论】:

    标签: python api instagram


    【解决方案1】:

    根据您的问题猜测,我认为followers 是带有dict 元素的list

    这意味着followers[0] 将是一个包含您的关注者信息的单个字典。如果您想显示该用户名,只需使用 followers[0]['username'] 不循环地获取它。

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

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

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

    希望对您有所帮助!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-04-12
      • 1970-01-01
      相关资源
      最近更新 更多