如何使用 Tweepy 检索特定用户的推文回复/评论?
这是我尝试过的代码,我想要一个除此之外的解决方案
def replies_from_tweet_id(tweet_id,username):
replies=[]
for tweet in tweepy.Cursor(api.search,q='to:'+username, result_type='recent',timeout=999999,tweet_mode='extended',count=3000).items():
if hasattr(tweet, 'in_reply_to_status_id_str'):
if (tweet.in_reply_to_status_id_str==str(tweet_id)):
replies.append(tweet)
with open('./Data/'+username+'/'+tweet_id+'.csv', 'w') as f:
csv_writer = csv.DictWriter(f, fieldnames=('text','date'))
csv_writer.writeheader()
for tweet in replies[:200]:
row = {'text': tweet.full_text.replace('\n', ' ').strip('@'+username),'date':tweet.created_at }
csv_writer.writerow(row)
This is the code I've tried and I want a solution apart from this one
def replies_from_tweet_id(tweet_id,username):
replies=[]
for tweet in tweepy.Cursor(api.search,q='to:'+username, result_type='recent',timeout=999999,tweet_mode='extended',count=3000).items():
if hasattr(tweet, 'in_reply_to_status_id_str'):
if (tweet.in_reply_to_status_id_str==str(tweet_id)):
replies.append(tweet)
with open('./Data/'+username+'/'+tweet_id+'.csv', 'w') as f:
csv_writer = csv.DictWriter(f, fieldnames=('text','date'))
csv_writer.writeheader()
for tweet in replies[:200]:
row = {'text': tweet.full_text.replace('\n', ' ').strip('@'+username),'date':tweet.created_at }
csv_writer.writerow(row)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用 Twitter API v2,您可以通过 对话 ID 查询从特定对话线程中检索推文。
With Twitter API v2, you can query by conversation ID to retrieve Tweets from a specific conversation thread.