TweePy For循环不循环所有数据

时间:2017-09-12 08:41:19

标签: python for-loop tweepy

使用此代码段:

user = api.get_user('xxxx')
print(user.followers_count)
for i in user.friends():
    print(i.screen_name)

跟随者计数的结果是700 但为什么在循环所有数据时只显示21行数据?

1 个答案:

答案 0 :(得分:0)

虽然可以获得用户所有关注者的姓名,但很可能会被禁止超出速率限制。

以下代码会告诉您用户拥有多少粉丝,然后列出关注该用户的所有用户名。

username = 'keely_bro'
userID = api.get_user(username)
print('User is followed by ' + str(userID.followers_count) + ' people')
print('usernames of followers: ')
for allFollowers in tweepy.Cursor(api.followers_ids, screen_name=username).pages():
    followerNames = [userID.screen_name for userID in api.lookup_users(allFollowers)]
    for follow in followerNames:
        print(follow)
相关问题