Python Tutorial 50 – Twitter Email Scraper Using Tweepy, Twitter API and Regular Expression

In this Python Tutorial, I would walk you through how to build a Twitter email scraper to grab the user emails using tweepy and Twitter. By the end of this tutorial, you can also explore how to utilize regular expression to extract text information from a paragraph.

twitter email scraper

In this Python Tutorial, I would walk you through how to build a Twitter email scraper to grab the user emails using Tweepy and Twitter. By the end of this tutorial, you can also explore how to utilize regular expression to extract text information from a paragraph.

Python modules: Tweepy, Twitter API, regular expressions

Twitter Email Scraper – Methodology to scrape the Twitter Profile Emails

Twitter API itself doesn’t provide the twitter user profile email address as it deals with privacy and GDPR compliance. But twitter profiles who are proactively looking for business collaboration usually put their contacts in the biography. Scraping that information like you manually eye out and collect is not violating the data privacy, as the user welcomes you to reach out to her or him.

So the methodology in this python tutorial would be scraping biography information and extracting the emails if having. Basically, the majority of users place their contacts there.

Twitter email scraper

Twitter Nickname or Twitter ID is either okay

Before starting scraping the biography information, you need to have a target-specific profile ID or nickname in place. Regarding this approach of scraping the ID or nickname, please refer to this article

Python Tutorial 34: Twitter Bot for Scraping Most Popular Topics and Influencer Profiles

Scrape Twitter User Biography Information Using Nickname

Take the Twitter Nickname for example. When a list of names is ready, we would use the Tweepy method called get_user() and the parameter screen_name. Basically, this method can call the specific Twitter user profile information, which includes biography information.

The response data format is mixed at the moment with JSON and the API response ID number. For parsing the JSON. We need to add this command user._json, which is only to get the user json data.

Then, part of the JSON data has a dataset called description. This is the biography information that the user uploads to her or his profile. We need to scrape it. If you have more than one user nickname, you need a loop

Twitter Email Scraper – Extract email address using regular expression

Biography information might include email address, website URL, social profiles, etc. You can customize the regular expression based on your needs. Here is the regular expression to extract email addresses.

[A-z0-9._%+-]+@[A-z0-9.-]+\.[A-z]{2,4}

In the Regexextract formula, the 1st position argument is to set the data source

iferror(Regexextract(jsonDescriptionData,"[A-z0-9._%+-]+@[A-z0-9.-]+\.[A-z]{2,4}"),"")

The 2nd positional argument is the formula to extract the emails.

Full Python Script of Twitter Email Scraper

If you are interested in the full Python script of Python Tutorial 50 – Twitter Email Scraper Using Tweepy, Twitter API, and regular expression, please subscribe to our newsletter by adding the message “Python Tutorial 50”. We would send you the script immediately to your mailbox.

Contact us

I hope you enjoy reading Python Tutorial 50 – Twitter Email Scraper Using Tweepy, Twitter API, and regular expression. If you did, please support us by doing one of the things listed below, because it always helps out our channel.

  • Support my channel through PayPal (paypal.me/Easy2digital)
  • Subscribe to my channel and turn on the notification bell Easy2Digital Youtube channel.
  • Follow and like my page Easy2Digital Facebook page
  • Share the article to your social network with the hashtag #easy2digital
  • Buy products with Easy2Digital 10% OFF Discount code (Easy2DigitalNewBuyers2021)
  • You sign up for our weekly newsletter to receive Easy2Digital latest articles, videos, and discount code on Buyfromlo products and digital software
  • Subscribe to our monthly membership through Patreon to enjoy exclusive benefits (www.patreon.com/louisludigital)