用Twython抓住用户粉丝

时间:2015-03-17 03:14:33

标签: python data-retrieval twython

我有获取特定用户关注者的代码,如下所示。我想要做的是进一步做到这一点不仅仅是抓住用户的粉丝,也是追随者自己的追随者。一个例子就是抓住Carl Icahns的追随者身份,然后让那些粉丝拥有自己的粉丝ID。因此,如果我关注Carl Icahn,我也可以检索所有关注者。此外,出于某种原因,我每次打电话都会抓住同样的5000名粉丝,而不是每次都获得不同的5000。有人可以帮我这个吗?我将不胜感激。

import logging
import time
import csv
import twython
import json

app_key = "**********"
app_secret = "**********"
oauth_token = "***********"
oauth_token_secret = "**************"

twitter = twython.Twython(app_key, app_secret, oauth_token, oauth_token_secret)

followers = twitter.get_followers_ids(screen_name = "Carl_C_Icahn")

for follower_id in followers:
    print ("Carl Icahn followers:", followers)

    with open('carlfollowers.txt', 'a') as outfile:
         json.dump(followers, outfile, sort_keys = True, indent = 4)

1 个答案:

答案 0 :(得分:0)

代码变化不大:

import logging  
import time  
import csv  
import twython  
import json  

app_key = "**********"  
app_secret = "**********"  
oauth_token = "***********"  
oauth_token_secret = "**************"  

twitter = twython.Twython(app_key, app_secret, oauth_token, oauth_token_secret)  

followers = twitter.get_followers_ids(screen_name = "Carl_C_Icahn")  

with open('carlfollowers.txt', 'a') as outfile:  
    for follower_id in followers:
        print("Carl Icahn follower:", follower_id)
        json.dump(follower_id, outfile, sort_keys = True, indent = 4)
相关问题