簡體   English   中英

如何從Tweepy獲取一條推文的全文

[英]How to get full text of a tweet from Tweepy

我正在使用Tweepy通過字符串查詢推文,當我這樣做時,它將以截斷的方式返回推文,例如“ the quick brown fox ju ...”。

如何獲得該推文的全文?

這是我的代碼的一部分

def get_tweets(self, query, count = 10):

    #this is main function that will query for 
    #a specified number of tweets

    #an empty list to store parsed tweets
    tweets = []

    a = self.api.get_status(912886007451676672, tweet_mode='extended')

    try:
        #call the api to fetch tweets
        fetched = self.api.search(q = query, rpp = int(count), tweet_mode="extended")

        #parsing tweets one by one
        for tweet in fetched:
            #empty dictionary to store required params of a tweet
            parsed_tweet = {}

            #saving text of tweet in dictionary
            parsed_tweet['text'] = self.api.get_status(tweet.id, tweet_mode='extended')._json['full_text']
            #saving the sentiments of the tweet
            parsed_tweet['sentiment'] = self.get_tweet_sentiment(tweet.full_text)
            parsed_tweet['subjectivity'] = self.get_tweet_subjectivity(tweet.full_text)
            #appending parsed tweet to tweets list
            #and only append once if there are rebtweets
            if tweet.retweet_count > 0:
                if parsed_tweet not in tweets:
                    tweets.append(parsed_tweet)
            else:
                tweets.append(parsed_tweet)

        return tweets

    except tweepy.TweepError as e:
        print("Error : " + str(e))

在擴展模式下使用full_text屬性

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM