尽管使用了扩展文本功能,Tweepy仍然不返回全文

时间:2019-02-20 01:20:21

标签: python mining

我正在使用tweepy下载有关特定主题的tweet,但是没有人遵循我的教程,因此无法将tweet输出为完整的tweet。总是有一个椭圆,在经过一定数量的字符后会被切掉。

这是我正在使用的代码

import json
import tweepy
from tweepy import OAuthHandler 
import csv
import sys
from twython import Twython
nonBmpMap = dict.fromkeys(range(0x10000, sys.maxunicode + 1), 0xfffd)
with open ('Twitter_Credentials.json') as cred_data:
info = json.load(cred_data)
consumer_Key = info['Consumer_Key']
consumer_Secret = info['Consumer_Secret']
access_Key = info['Access_Key']
access_Secret = info['Access_Secret']


maxTweets = int(input('Enter the Number of tweets that you want to extract '))
userTopic = input('What topic do you want to search for ')
topic = ('"' + userTopic + '"')
tweetCount = 0

auth = OAuthHandler(consumer_Key, consumer_Secret)
auth.set_access_token(access_Key, access_Secret)
api = tweepy.API(auth, wait_on_rate_limit=True)
tweets = api.search(q=topic, count=maxTweets, tweet_mode= 'extended')

for tweet in tweets:
    tweetCount = (tweetCount+1)
    with open ('TweetsAbout' + userTopic, 'a', encoding='utf-8') as the_File:
        print(tweet.full_text.translate(nonBmpMap))
        tweet = (str(tweet.full_text).translate(nonBmpMap).replace(',','').replace('|','').replace('\n','').replace('’','\'').replace('…',"end"))
        the_File.write(tweet + "\n")
        print('Extracted ' + str(tweetCount) + ' tweets about ' + topic)

1 个答案:

答案 0 :(得分:0)

尝试一下,看看是否有效!

-

您尝试提取的所有文本都应位于def push_value(**context): context['ti'].xcom_push(key='my_key', value='my_value') def use_pushed_val(**context): value_from_parent = context['ti'].xcom_pull(task_ids=t1.task_id, key='my_key') 中。祝你好运!