Tweepy Twitter 获取特定用户的所有推文回复 [英] Tweepy Twitter get all tweet replies of particular user

查看:43
本文介绍了Tweepy Twitter 获取特定用户的所有推文回复的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试获取此特定用户的所有回复.所以这个特定用户的 reply_to_user_id_str 为 151791801.我试图打印出所有的回复,但我不确定如何打印.但是,我只能打印出其中的 1 个回复.谁能帮我打印所有回复?

I am trying to get all replies of this particular user. So this particular user have reply_to_user_id_str of 151791801. I tried to print out all the replies but I'm not sure how. However, I only manage to print out only 1 of the replies. Can anyone help me how to print out all the replies?

我的代码是:

for page in tweepy.Cursor(api.user_timeline, id="253346744").pages(1):
    for item in page:
            if item.in_reply_to_user_id_str == "151791801":
                print item.text
                a = api.get_status(item.in_reply_to_status_id_str)
                print a.text

推荐答案

首先,找到您与服务提供商对话的转推主题:

First, find the retweet thread of your conversation with your service provider:

# Find the last tweet
for page in tweepy.Cursor(api.user_timeline, id="253346744").pages(1):
    for item in page:
        if item.in_reply_to_user_id_str == "151791801":
            last_tweet = item

变量 last tweet 将包含他们最后转发给您的推文.从那里,您可以循环回到原始推文:

The variable last tweet will contain their last retweet to you. From there, you can loop back to your original tweet:

# Loop until the original tweet
while True:
    print(last_tweet.text)
    prev_tweet = api.get_status(last_tweet.in_reply_to_status_id_str)
    last_tweet = prev_tweet
    if not last_tweet.in_reply_to_status_id_str:
        break

它不漂亮,但它完成了工作.祝你好运!

It's not pretty, but it gets the job done. Good luck!

这篇关于Tweepy Twitter 获取特定用户的所有推文回复的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆