How to get the full text of a tweet using tweepy?

雨燕双飞 提交于 2021-02-17 05:33:07

问题


I'm using tweepy.Cursor to extract past tweets of a particular topic, however if the tweet is really long it truncates it. I am using the full_text property to be True, but still it doesn't fix it. How to fix this?

MY code is here:

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()

回答1:


you have to explicitly access the field called "full_text". You can try something like this:

# 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"])

You can extract as much info as you need and then write it into a CSV file or whatever you want.

I recomend you extract the tweets into a json file so you can easily check all the fields it offers to you.

Hope it helps!

Edit: If the retrieved tweet is a RT, the full text will be in result["retweeted_status"]["full_text"]



来源:https://stackoverflow.com/questions/53161459/how-to-get-the-full-text-of-a-tweet-using-tweepy

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!