python - 我如何在 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
解决方案
从你的问题猜测,我认为这followers
是一个list
元素dict
。
这意味着这followers[0]
将是一个包含您的关注者之一的信息的单个字典。如果要显示该用户名,只需使用followers[0]['username']
.
如果您想显示所有关注者,请遍历list
:
for follower in followers:
print(follower['username'])
额外提示:知道您可以list
使用 Python 的漂亮列表理解轻松获取您的关注者的用户名:[follower['username'] for follower in followers]
.
希望这有帮助!
推荐阅读
- mysql - 我想创建数据库来管理三种类型的用户?
- javascript - Facebook 聊天插件获取发件人 URL
- javascript - 如何在 React Native 中制作自定义形状
- java - 如何使用 POLLENRICH 读取 JSON 文件内容
- r - 将 sf 对象传递给 ggmap R 时指定数字箱
- java - Spark - 如何获取随机唯一行
- python - 选择单选按钮后的 PySimpleGUI 文本框输出信息
- html - 在更改 SVG 宽度时保持字母间距不变
- queue - NiFi - 处理后的 JMS 确认
- jenkins - 关于管道语法的 Kubernetes Jenkins 插件问题