Sometimes it’s useful to take a huge sample of tweets that include a specific keyword or hashtag. This can help marketers to identify social trends, content opportunities, and areas to enter the conversation.

While there are several tools available to provide a general analysis of social trends, few give you access to the full data set. This script offers a free way to scrape as many tweets as you require related to a single keyword or hashtag and then insert them into a corpus for analysis.

In order for the below code to work, you will need to have installed Python. After you opened Python in the command console, you will also need to run the command:

credentialsexport TWITTER=""

Once you’ve done this, you can then run a python file that contains the following code:

from nltk.twitter import Twitter 
tw = Twitter() 
 
print (""" ==================================================== \n Twitter Keyword Live Stream\n ==================================================== """) 
 
print ("Enter your Keyword")
keyword = raw_input(">") 
print ("Set Number of Tweets for corpus") 
f_setsize = raw_input(">") 
setsize = int(f_setsize) 
tw.tweets(keywords=keyword, stream=False, limit=setsize) 
 
print (""" ==================================================== \n FINISHED.""")
 
print (""" ==================================================== """) print (A_Stream) 
Follow the commands and then copy the output into a notepad document for analysis in your favorite corpus tool (I’ll forever recommend AntConc).