How to Listen to Competitors on Twitter

Share on facebook
Share on twitter
Share on linkedin
twitter-listening

Twitter is a gold mine of information. You can track what content your audience is most engaged with, you can see who is the most influential in your space, and you can spy on your competitors.

You may be wondering, “How am I supposed to find this information?”

Luckily, there are many Twitter scraping libraries out there. I prefer to use twint. It acts as a headless Chrome browser and opens Twitter without logging in to scrape the application without an API Key.

Install Twitter Scraping Library

In order to install the twint library to your computer, you will want to open up your Terminal and type in the following command.

pip install twint

For the first step of our script, we will import “twint”, the Twitter scraping Library at the beginning of our file.

import twint

Find Your Competitor’s Handle

In order to start listening to a specific competitor, you want to create a variable called “competitor” that stores the String of your competitor’s handle with a single or double quote.

competitor = 'YOUR_COMPETITORS_TWITTER_HANDLE'

Config Your Twitter Search

In order to use Twint, we will need to create a Config object that we pass into the Twint search function. We will store our config file in a variable called “twitter_config”. We will create this file by calling twint.Config().

twitter_config = twint.Config()

In order to pull the information on this competitor, we need to set the Username variable of our Config object as our competitor variable.

twitter_config.Username = competitor

Next, we want to set the Output variable of our config file as the Username we’re searching with the “.csv” file marker at the end. Additionally, we need to set the Config to store the data as a CSV.

twitter_config.Output = twitter_config.Username + ".csv"

twitter_config.Store_csv = True

Finally, we want to call the Search function that is within the run directory of twint by passing in our Config object.

twint.run.Search(twitter_config)

I ran this function on my own twitter handle and it returned the following information. You can see all my twitter data at this link.

Add this code to your IDE and test it out on a competitor or a person you really respect.