热线电话:13121318867

登录
2019-03-29 阅读量: 863
如何使用Tweepy提取推文

这里介绍Tweepy作为一种使用Python以相当简单的方式访问Twitter数据的工具。我们可以收集不同类型的数据,明显关注“推文”对象。一旦我们收集了一些数据,分析应用程序的可能性就是无穷无尽的。

提取推文的一个这样的应用是情感或情绪分析。通过对每个单词进行标记并对该数据应用机器学习算法,可以从推文中获得用户的情绪。这种情绪或情绪检测在世界范围内使用,并将在未来广泛使用。


# 200 tweets to be extracted

number_of_tweets=200

tweets = api.user_timeline(screen_name=username)

# Empty Array

tmp=[] 

# create array of tweet information: username, 

# tweet id, date/time, text

tweets_for_csv = [tweet.text for tweet in tweets] # CSV file created 

for j in tweets_for_csv:

# Appending tweets to the empty array tmp

tmp.append(j) 

# Printing the tweets

print(tmp)

# Driver code

if __name__ == '__main__':

# Here goes the twitter handle for the user

# whose tweets are to be extracted.

get_tweets("twitter-handle") 

25.4271
2
关注作者
收藏
评论(0)

发表评论

暂无数据
推荐帖子