繁体   English   中英

提取完整推文 Tweepy Python

[英]Extract full tweet Tweepy Python

我找不到获取推文全文的方法,我已经激活了所有内容,tweet_mode="extended" 并打印了 tweet.full_text,但它不断收到修剪后的推文,我直接查看了 tweet._json而且那里也被修剪了 我不明白为什么

import tweepy
import configparser
from datetime import datetime

def apiTwitter(): #Para conectarse a twitter y scrapear con su api, devuelve objeto de tweepy cheto para scrapear twitter
    # read credentials
    config = configparser.ConfigParser()
    config.read('credentialsTwitter.ini')

    api_key = config['twitter']['api_key']
    api_key_secret = config['twitter']['api_key_secret']

    access_token = config['twitter']['access_token']
    access_token_secret = config['twitter']['access_token_secret']

    # authentication
    auth = tweepy.OAuthHandler(api_key,api_key_secret)
    auth.set_access_token(access_token,access_token_secret)

    api=tweepy.API(auth)

    return api


api=apiTwitter() #Con api ahora podemos scrapear todo twitter de forma sencilla
tweets = api.user_timeline(screen_name='kowaalski_',tweet_mode="extended", count=1)
tweet=tweets[0]
#print(tweet._json)
print(f'Tweet text: {tweet.full_text}')

这是因为第一条推文是转推,转推的full_text属性仍然可以被截断。 您必须访问转推状态的full_text属性。

基本示例:

try:
    print(tweet.retweeted_status.full_text)
except AttributeError:  # So this is not a Retweet
    print(tweet.full_text)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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