import tweepy
import csv
consumer_key = "?"
consumer_secret = "?"
access_token = "?"
access_token_secret = "?"
auth = tweepy.OAuthHandler(consumer_key,consumer_secret)
auth.set_access_token(access_token,access_token_secret)
api = tweepy.API(auth)
search_tweets = api.search('trump',count=1,tweet_mode='extended')
print(search_tweets[0].full_text)
print(search_tweets[0].id)
输出是以下推文
RT @CREWcrew: When Ivanka Trump has business interests across the world,we have to
ask if she’s representing the United States or her busi…
967462205561212929
这是截断的,虽然我使用了tweet_mode =’extended’.
我怎样才能提取全文?
最佳答案
我和你最近遇到了同样的问题,这只发生在推文上,我发现你可以在这里找到全文:tweet._json [‘retweeted_status’] [‘full_text’]
代码段:
...
search_tweets = api.search('trump',tweet_mode='extended')
for tweet in search_tweets:
if 'retweeted_status' in tweet._json:
print(tweet._json['retweeted_status']['full_text'])
else:
print(tweet.full_text)
...
编辑另请注意,这不会显示RT @ ….在文本的开头,您可能想在文本的开头添加RT,无论适合您.
retweet_text = 'RT @ ' + api.get_user(tweet.retweeted_status.user.id_str).screen_name