我如何从Twitter获取全文?我想使用tweet_mode和full_text ..我如何在哪里使用?

时间:2019-06-03 15:11:02

标签: python twitter tweepy sentiment-analysis data-extraction

import tweepy

import pandas as pd                  

import matplotlib.pyplot as plt      

pd.set_option('display.unicode.east_asian_width', True)


consumerKey = 'somekey'

consumerSecret = 'somesecret'

auth = tweepy.OAuthHandler(consumer_key=consumerKey, 
    consumer_secret=consumerSecret)

api = tweepy.API(auth, wait_on_rate_limit=True)

result = api.search(q='Swiggy')

len(result)

tweet = result[0] 

for param in dir(tweet):

 if not param.startswith("_"):
        print("%s : %s\n" % (param, eval('tweet.'+param)))

results = []

for tweet in tweepy.Cursor(api.search, q='Swiggy').items(7000):
    results.append(tweet)

print(len(results))


def toDataFrame(tweets):

    DataSet = pd.DataFrame()

    DataSet['tweetID'] = [tweet.id for tweet in tweets]
    DataSet['tweetText'] = [tweet.text for tweet in tweets]
    DataSet['tweetRetweetCt'] = [tweet.retweet_count for tweet 
    in tweets]
    DataSet['tweetFavoriteCt'] = [tweet.favorite_count for tweet 
    in tweets]
    DataSet['tweetSource'] = [tweet.source for tweet in tweets]
    DataSet['tweetCreated'] = [tweet.created_at for tweet in tweets]

    DataSet['userID'] = [tweet.user.id for tweet in tweets]
    DataSet['userScreen'] = [tweet.user.screen_name for tweet 
    in tweets]
    DataSet['userName'] = [tweet.user.name for tweet in tweets]
    DataSet['userCreateDt'] = [tweet.user.created_at for tweet 
    in tweets]
    DataSet['userDesc'] = [tweet.user.description for tweet in tweets]
    DataSet['userFollowerCt'] = [tweet.user.followers_count for tweet 
    in tweets]
    DataSet['userFriendsCt'] = [tweet.user.friends_count for tweet 
    in tweets]
    DataSet['userLocation'] = [tweet.user.location for tweet in tweets]
    DataSet['userTimezone'] = [tweet.user.time_zone for tweet 
    in tweets]

    return DataSet

DataSet = toDataFrame(results)

0 个答案:

没有答案