简体   繁体   中英

tweepy Status object (tweet) has no attribute .text

using the Tweepy Python library I connected a Twitter account's credentials and stream real-time tweets related to a term of interest and then, I want to save them into a.txt file.

and then I want to read all the data we gathered into a pandas DataFrame

How could I do it, please.

This is my code: cursor = tweepy.Cursor(api.user_timeline, id='CarrefourFrance',tweet_mode='extended').items(33)


with open('t.txt', 'w') as f:
    for tweet in cursor:
        try:
            f.write('{}\n'.format(tweet.text.encode("utf-8")))
        except UnicodeEncodeError as e:
            print(e)

this is the error: AttributeError: 'Status' object has no attribute 'text'

Maybe you should try change tweet.text to tweet.full_text

Or something like this:

results = api.search(q=query, lang=language, count=tweetCount, tweet_mode='extended')
for tweet in results:
        print(tweet.full_text)

For reference: https://github.com/tweepy/tweepy/issues/878

And see the documentation for extended mode:

When using extended mode, the text attribute of Status objects returned by tweepy.API methods is replaced by a full_text attribute, which contains the entire untruncated text of the Tweet.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM