加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Python > 正文

python – tweepy:使用tweet_mode =’extended’时截断的推文

发布时间:2020-12-16 22:30:17 所属栏目:Python 来源:网络整理
导读:这是我在python中的代码 import tweepyimport csvconsumer_key = "?"consumer_secret = "?"access_token = "?"access_token_secret = "?"auth = tweepy.OAuthHandler(consumer_key,consumer_secret)auth.set_access_token(access_token,access_token_secret)

这是我在python中的代码

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,无论适合您.

编辑2
您可以获取推文作者的姓名,并将其添加为开头,如下所示

retweet_text = 'RT @ ' + api.get_user(tweet.retweeted_status.user.id_str).screen_name

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读