How to Scrape Favorite Tweets of any Twitter User from Command Line

0 Comments
Editor Ratings:
User Ratings:
[Total: 0    Average: 0/5]




In this post, I will talk about a free command line tool to scrape favorite tweets of any Twitter user. The tool is called Twint and it can scrape through the favorites section of a Twitter user and download the data. All it needs is the Twitter handle of the target user and starts getting tweets that you can save wherever you want. The scrapping process is slow but works like charm.

In the scraped data, it gets you the tweet id, tweet text, twitter handle of the target tweet owner, URL of the image if there is an image in tweet, and time. You can get this data in a tabular manner but not CSV or Excel. To convert it to Excel or CSV, you will have to some additional modifications.

If you want to get the tweets which are marked as favorite then you can use this tool. You just have to install it once and then execute a simple command and then save the data. It can show the extracted data on the console or you can use some extra switches to save this data in a file. Also, not just scraping favorite tweets but if you want to scrape regular tweets from a user’s profile then you can do that.

Twint scraping tweets in action

How to Scrape Favorite Tweets of any Twitter User from Command Line?

To install this tool and get it running you will need Python. After that, no matter what platforms you are , just execute the following command it will install the CLI of this tool and then you can start using it. This is an open source tool to scrape Twitter and you can read about its other functions on GitHub.

Run this command and then wait till the tool installs completely. After successful installation, it will all ready to be used.

pip install -e git+https://github.com/twintproject/twint.git#egg=twint

To scrape through, someone’s favorite list on Twitter, enter the following command and let it do its work. It will time based on the number of favorites you want to scrape. Also, do note that, following command is the syntax and you will have to replace then “UserName” with the Twitter handle of the target user.

twint -u sulemanelahi2 --favorites

Twint scraping tweets in action

If you want to save then data that scrapes to a file then simply add “> filename.txt” at the end of the above command. It will then save then tweets data in a file “filename.txt” which will be created in the current working directory.

This way, you can always use this simple command line tool to easily scrape through anyone’s favorite list on Twitter. And on the documentation page of this tool, you can see other commands and advanced switches that you can use. If you want to use this on your other applications then it can work as a library too.

Final thoughts

Twint is probably the most rated Twitter data scraper on GitHub right now. What is best about it is that it can do its work without relying on the Twitter API. You just install it, run the command and get the data. If you just want to see the data then you can see that on the command interface. Otherwise, you can download that as well on your PC if you want to.

Editor Ratings:
User Ratings:
[Total: 0    Average: 0/5]
Free/Paid: Free