簡體   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