【问题标题】:How to get the full text of a tweet using tweepy?如何使用 tweepy 获取推文的全文?
【发布时间】:2019-04-09 05:30:49
【问题描述】:

我正在使用 tweepy.Cursor 提取特定主题的过去推文,但是如果推文真的很长,它会截断它。我正在使用 full_text 属性为 True,但它仍然无法修复它。如何解决这个问题?

我的代码在这里:

auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)

API = tweepy.API(auth)

csvFile = open('tweets2.csv', 'a')
csvWriter = csv.writer(csvFile)


for tweet in tweepy.Cursor(API.search,q="$EURUSD",count=1000,
                       lang="en", full_text = True).items():

csvWriter.writerow([tweet.created_at, tweet.text.encode('utf-8')])

csvFile.close()

【问题讨论】:

    标签: tweepy


    【解决方案1】:

    您必须显式访问名为“full_text”的字段。 你可以试试这样的:

    # First you get the tweets in a json object
    results = [status._json for status in tweepy.Cursor(API.search, q="$EURUSD", count=1000, tweet_mode='extended', lang='en').items()]
    
    # Now you can iterate over 'results' and store the complete message from each tweet.
        my_tweets = []
        for result in results:
            my_tweets.append(result["full_text"])
    

    您可以根据需要提取尽可能多的信息,然后将其写入 CSV 文件或任何您想要的文件。

    我建议您将推文提取到 json 文件中,以便您可以轻松检查它提供给您的所有字段。

    希望对你有帮助!

    编辑:如果检索到的推文是RT,则全文将在result["retweeted_status"]["full_text"]

    【讨论】:

      猜你喜欢
      • 2019-05-06
      • 2019-02-25
      • 1970-01-01
      • 2019-03-06
      • 2020-09-02
      • 1970-01-01
      • 2020-09-07
      • 1970-01-01
      • 2015-06-17
      相关资源
      最近更新 更多