使用 tweepy 游标获取用户推文,不包括转推
Get users tweets excluding retweets using tweepy cursor
我想为其 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')
过滤转推,但如果用户有转推,代码将仅 return(400 - 转推)条推文。
据我所知,Cursor 中没有排除转推的选项。有什么办法可以解决这个问题吗?
回复此问题已解决。 python-twitter
API 包装器提供了一个参数 include_rts=False
来过滤掉转推