Python Web Scraping Part: 5

iOSTom
Python + Data Science + Web
4 min readJan 27, 2020
Tweepy

Over the past few articles I have talked about python, web scraping and digital marketing. In this article I am going to explain how to use python and tweepy to increase your social media presence.

I am going to show you how to build a twitter bot using tweepy that will find users, like tweets, retweet and interact with users.

First lets create our virtual environment, if you are not using a virtual environment with python start, you will thank me later. Next activate your environment and do a pip install tweepy.

Create a new python file called twitter_bot.py, I am not sold on my bot architecture and will probably refactor and do a follow-up article at a later date. I chose to create a class with a bunch of methods.

This is find_tweet_topic_reply_with_message

Using twitter_bot and find_tweet_topic_reply_with_message

Output

I think this is a great way to get your media out there, problem is I am amusing everyone who posted with #web+crawler cares about my articles and I still do not know if I have retweeted a bot or a real tweet. I am sure I will find an answer soon. When building a twitter bot I need to ensure my bot can send tweets, retweet and follow users. I am hoping the below code will help me increase my view count and followers.

I am passing a hashtag and searching twitter for the first 10 tweets. Next I loop through each tweet and display the message, “Found Tweet by @” followed by their twitter name. I check the tweet to see if I have retweeted it or liked it. Next, I check if I am following the user, if I am not I start, and lastly I check for errors.

My twitter bot has the capabilities to search twitter for a keyword, like the first 100 tweets and then go back and reply to every like in a retweet and mention that like by it’s twitter handler telling them to check out my articles.

It also retweets and follows the user, I do not know about how twitter views this but I think it is pretty cool. In the next article I am going to take a deeper dive it tweepy and analyze tweets with natural language processing. Stay tuned and also check out some of my articles about the aws deeplens or other python articles. If you liked this article give it a couple of claps or leave a comment below.

--

--

iOSTom
Python + Data Science + Web

iOS Developer, Go, Java, C#, Blockchain enthusiast, Data junkie