【问题标题】:Checking if tweet is in reply to deleted tweet检查推文是否是对已删除推文的回复
【发布时间】:2022-01-25 08:34:03
【问题描述】:

我正在编写一个程序来抓取用户在两个特定日期之间的推文,同时确保它们不是转发或回复。我正在使用 snscrapetweepy

for i, tweet in enumerate(sntwitter.TwitterSearchScraper('from:' + lines[x] + ' since:' + startDate + ' until:' + endDate).get_items()):
    if tweet.retweetedTweet is None and tweet.inReplyToTweetId is None and tweet.inReplyToUser is None:

这是我要检查的内容,但是,如果推文是对已删除的推文的回复,则该推文不再被视为回复,并且检查通过 None。有没有解决的办法?我正在考虑从 Tesco 和 Sainsburys 等大公司提取推文,然后手动对他们的推文进行手动排序会很乏味,我想找到一种方法在代码中解决这个问题。

this tweet 就是一个例子,因为代码通过了inReplyToTweetId is None 的检查

任何帮助将不胜感激,谢谢。

【问题讨论】:

    标签: python twitter tweepy


    【解决方案1】:

    我实际上比我想象的要快得多。原来,在推文对象中,mentionedUsers 数组对于这些特定推文是空的,所以我添加了以下 if 语句来解决问题:

    if not ('@' in tweet.content and not tweet.mentionedUsers):
    

    这只是检查用户在推文的实际文本中是否有提及(@ 符号)以及 mentionedUsers 数组是否为空以将其丢弃为回复。

    【讨论】:

      猜你喜欢
      • 2021-07-17
      • 2018-10-07
      • 2018-09-03
      • 2013-09-23
      • 1970-01-01
      • 2021-09-17
      • 1970-01-01
      • 2012-09-16
      • 1970-01-01
      相关资源
      最近更新 更多