Skip to main content
 首页 » 编程设计

python之使用 tweepy 游标获取用户推文,不包括转推

2024年12月31日7sharpest

我想为其 ID 在列表中的每个用户准确提取 400 条推文。

我正在使用 Tweepy 和 Cursor 执行此操作,我的代码如下所示:

for user_id in users: 
    for tweet in tweepy.Cursor( 
                api.user_timeline, 
                id=user_id 
    ).items(400) 

上面的代码检索了所有最近的 (400) 条推文,但它也包括我不想包含的转推。

可以使用 if hasattr(tweet, 'retweeted_status') 过滤转推,但如果用户有转推,代码将只返回(400 - 转推)条推文。

据我所知,Cursor 中没有排除转推的选项。有什么办法可以解决这个问题吗?

请您参考如下方法:

回复,因为这个问题已经解决了。 python-twitter API 包装器提供了一个参数 include_rts=False 来过滤掉转发