Scrape Twitter Data in Python with Twitterscraper Module

Ken Jee · Beginner ·📰 AI News & Updates ·7y ago

Key Takeaways

The video demonstrates how to scrape Twitter data using the Twitterscraper Python module, allowing users to retrieve tweets without needing a Twitter API key. The module's functionality is showcased by scraping tweets related to the Notre Dame fire and transforming the data into a pandas DataFrame for further analysis.

Full Transcript

hello everyone ken here today I'm showing you how to scrape Twitter data using Python and the Twitter scraper module so on my screen is the Twitter scraper documentation it is also in the description below as you can see you can do it from the command line but I prefer to do it from the notebook it allows me to read it in directly into a data frame and allows me to manipulate it from there to get started we install it pip install Twitter Ripper I've obviously already downloaded it so all the requirements are met here now I'm going to open up spider which is my ID of choice for data science so from Twitter scraper and for query weeks now we're also going to import date/time because we want to set a date range for the tweets and we're going to import pandas because we want to turn this into a data frame after without so the first thing we're going to do is query tweets takes a couple parameters the first one and a relevant one to us is begin date is equal to so all in a query is something recent I'm gonna do the notre-dame fire that happened very recently that'll be a good example to show us something that is relevant and a lot of the information associated with that on Twitter will also an end date we're gonna do tomorrow today is the 17th for me and that's because it just takes all of yesterday's yeah well today's data as well and that's relevant if you just want to do a time window for example in one of my previous videos I did the timing around a movie premiere we can also put in a limit so let's say this is a really really popular topic we can set a limit of a thousand or so so we don't go crazy we don't have millions and millions of tweets that would take forever to download now we can also set a language so lang equals English in this case if we're doing the Notre Dame fire there's gonna be a lot of French tweets I would expect so we'd want to filter those out so it's understandable for me mainly if we wanted to just look at one person tweets we could also just query them we would set the user is equal to let's just say Rio Trump if you wanted to here is wacky comments on the Notre Dame fire you'd be able to type that in and filter specifically for that now for the real magic here we just query tweets so and we put in our parameters right here we're asking for better than fire which is our key component that we're gonna query you can also put hashtags anything relevant that you look like there we do begin date equals begin date end date equals we're gonna set the limit and so we can load all of this in and this should take just a couple minutes if you're doing anything over ten hundred thousand it can take up to you know twenty thirty minutes actually wrong the way they do this is they just have from my understanding a bunch of threads hitting Twitter so it will it depends fairly heavily on the processing power of your computer if you want to increase the speed or not so looks like we got a thousand twenty which is pretty close to our limit so I can't complain too much it it isn't super exact just because of I guess the the structure of the back end there now we want to make this relevant to us as you can see the tweets here are just in tweet objects that don't really mean it down to us yet so let's transform this into a data frame so data frame is equal to all right so after doing that we have all of our Twitter data we have the username we have the number of likes replies etc you can filter by that if you want or you can order by it etc and we also have all of the tweets as you can see there's a ton of duplicates so that's something that I like to remove duplicates of a lot of them are news related most of the URL and the actual username of the person who posted these tweets you can do a lot of really interesting stuff with this I've done the sentiment analysis in the past on Captain Marvel the movie premiere and you can see that above you can also combine it all make a word cloud related to the event or the topic that you're covering and there's plenty of other text-based analysis that you can do with this information this is a great tool it's fast easy and free and I highly recommend that you use it thank you so much for watching my video if you enjoyed it please like if you want to see more content like this please subscribe have a great one

Original Description

In this video, I show you how to scrape twitter data using the twitterscraper python module. #DataScience #TwitterScraper #WebScraping https://github.com/taspinar/twitterscraper This module is great because it does not require you to get an API key from twitter. It also lets you go back beyond the 2 week paywall that twitter has. #KenJee ⭕ Subscribe: https://www.youtube.com/c/kenjee1?sub_confirmation=1 🎙 Listen to My Podcast: https://www.youtube.com/c/KensNearestNeighborsPodcast 🕸 Check out My Website - https://kennethjee.com/ ✍️Sign up for My Newsletter - https://www.kennethjee.com/newsletter 📚 Books and Products I use - https://www.amazon.com/shop/kenjee (affiliate link) Partners & Affiliates 🌟 365 Data Science - Courses ( 57% Annual Discount): https://365datascience.pxf.io/P0jbBY 🌟 Interview Query - https://www.interviewquery.com/?ref=kenjee MORE DATA SCIENCE CONTENT HERE: 🐤My Twitter - https://twitter.com/KenJee_DS 👔 LinkedIn - https://www.linkedin.com/in/kenjee/ 📈 Kaggle - https://www.kaggle.com/kenjee 📑 Medium Articles - https://medium.com/@kenneth.b.jee 💻 Github - https://github.com/PlayingNumbers 🏀 My Sports Blog -https://www.playingnumbers.com Check These Videos Out Next! My Leaderboard Project: https://www.youtube.com/watch?v=myhoWUrSP7o&ab_channel=KenJee 66 Days of Data: https://www.youtube.com/watch?v=qV_AlRwhI3I&ab_channel=KenJee How I Would Learn Data Science in 2021: https://www.youtube.com/watch?v=41Clrh6nv1s&ab_channel=KenJee My Playlists Data Science Beginners: https://www.youtube.com/playlist?list=PL2zq7klxX5ATMsmyRazei7ZXkP1GHt-vs Project From Scratch: https://www.youtube.com/watch?v=MpF9HENQjDo&list=PL2zq7klxX5ASFejJj80ob9ZAnBHdz5O1t&ab_channel=KenJee Kaggle Projects: https://www.youtube.com/playlist?list=PL2zq7klxX5AQXzNSLtc_LEKFPh2mAvHIO
Watch on YouTube ↗ (saves to browser)
Sign in to unlock AI tutor explanation · ⚡30

Playlist

Uploads from Ken Jee · Ken Jee · 19 of 60

1 Predicting Crypto-Currency Price Using RNN lSTM & GRU
Predicting Crypto-Currency Price Using RNN lSTM & GRU
Ken Jee
2 Predicting Season Long NBA Wins Using Multiple Linear Regression
Predicting Season Long NBA Wins Using Multiple Linear Regression
Ken Jee
3 How I Became A Data Scientist From a Business Background
How I Became A Data Scientist From a Business Background
Ken Jee
4 Should You Get A Masters in Data Science?
Should You Get A Masters in Data Science?
Ken Jee
5 How to Simulate NBA Games in Python
How to Simulate NBA Games in Python
Ken Jee
6 Demystifying Data Science Roles
Demystifying Data Science Roles
Ken Jee
7 The Best Way to Predict NBA Minutes Played
The Best Way to Predict NBA Minutes Played
Ken Jee
8 IT'S NOT TOO LATE TO LEARN CODE!
IT'S NOT TOO LATE TO LEARN CODE!
Ken Jee
9 My Top 5 Data Science Resources for 2019
My Top 5 Data Science Resources for 2019
Ken Jee
10 Watch This Before Applying to Data Science Jobs
Watch This Before Applying to Data Science Jobs
Ken Jee
11 Where YOU Should Start With Data Science Projects
Where YOU Should Start With Data Science Projects
Ken Jee
12 Welcome To My Channel | Ken Jee | Data Science
Welcome To My Channel | Ken Jee | Data Science
Ken Jee
13 Why You DON'T Want to be a WFH Data Scientist
Why You DON'T Want to be a WFH Data Scientist
Ken Jee
14 Was Captain Marvel Bad? A Sentiment Analysis of Twitter Data
Was Captain Marvel Bad? A Sentiment Analysis of Twitter Data
Ken Jee
15 Data Science, Machine Learning, and AI: What's the Difference?
Data Science, Machine Learning, and AI: What's the Difference?
Ken Jee
16 Data Science: Startup vs. Large Corporation
Data Science: Startup vs. Large Corporation
Ken Jee
17 Where to Look for Data Science Jobs
Where to Look for Data Science Jobs
Ken Jee
18 Work From Home Data Scientist: Day in the Life
Work From Home Data Scientist: Day in the Life
Ken Jee
Scrape Twitter Data in Python with Twitterscraper Module
Scrape Twitter Data in Python with Twitterscraper Module
Ken Jee
20 Should You Learn R for Data Science?
Should You Learn R for Data Science?
Ken Jee
21 NASA Physicist Turned Data Scientist (Tim Bowling) - KNN EP. 02
NASA Physicist Turned Data Scientist (Tim Bowling) - KNN EP. 02
Ken Jee
22 I Wish I Had Known THIS Before Starting in Data Science
I Wish I Had Known THIS Before Starting in Data Science
Ken Jee
23 What I Learned From My Three Degrees
What I Learned From My Three Degrees
Ken Jee
24 Most Data Science Hopefuls Overlook This Important Skill
Most Data Science Hopefuls Overlook This Important Skill
Ken Jee
25 Golf STATS: Strokes Gained Explained
Golf STATS: Strokes Gained Explained
Ken Jee
26 My Top 5 Data Science Internship Tips
My Top 5 Data Science Internship Tips
Ken Jee
27 How I Got My First Data Science Internship (And How You Can Land One)
How I Got My First Data Science Internship (And How You Can Land One)
Ken Jee
28 Data Science: Pros and Cons
Data Science: Pros and Cons
Ken Jee
29 Data Science Fundamentals: Data Exploration in Python (Pandas)
Data Science Fundamentals: Data Exploration in Python (Pandas)
Ken Jee
30 Data Science Fundamentals: Data Manipulation in Python (Pandas)
Data Science Fundamentals: Data Manipulation in Python (Pandas)
Ken Jee
31 What Does a Data Scientist Actually Do?
What Does a Data Scientist Actually Do?
Ken Jee
32 The Projects You Should Do To Get A Data Science Job
The Projects You Should Do To Get A Data Science Job
Ken Jee
33 Take Your Data Science Projects From Good to Great
Take Your Data Science Projects From Good to Great
Ken Jee
34 How To Get Data Science Experience (Without a Job)
How To Get Data Science Experience (Without a Job)
Ken Jee
35 Data Science Fundamentals: Data Cleaning in Python
Data Science Fundamentals: Data Cleaning in Python
Ken Jee
36 Is Data Science Right For You?
Is Data Science Right For You?
Ken Jee
37 Thank You For The Support | What's Next | Ken Jee | Data Science
Thank You For The Support | What's Next | Ken Jee | Data Science
Ken Jee
38 How To Build A Word Cloud From Scraped Data (Python)
How To Build A Word Cloud From Scraped Data (Python)
Ken Jee
39 6 Habits of Successful Data Scientists
6 Habits of Successful Data Scientists
Ken Jee
40 How Far Should the NBA 3-Point Line Actually Be?
How Far Should the NBA 3-Point Line Actually Be?
Ken Jee
41 How to Stay Productive & Motivated When Learning Data Science
How to Stay Productive & Motivated When Learning Data Science
Ken Jee
42 Why is Balance Important in Data Science?
Why is Balance Important in Data Science?
Ken Jee
43 By The Numbers: Where Should The NBA Put a 4 Point Line?
By The Numbers: Where Should The NBA Put a 4 Point Line?
Ken Jee
44 Why Selling Is An Important Data Science Skill
Why Selling Is An Important Data Science Skill
Ken Jee
45 Applying Data Science To My YouTube Data: My Surprising Findings
Applying Data Science To My YouTube Data: My Surprising Findings
Ken Jee
46 9 Ways You Can Make Extra Income as a Data Scientist
9 Ways You Can Make Extra Income as a Data Scientist
Ken Jee
47 Sports Analytics 101: The Pythagorean Theorem of Sports
Sports Analytics 101: The Pythagorean Theorem of Sports
Ken Jee
48 Golf: Would You Rather Be the LONGEST or STRAIGHTEST Driver on the PGA Tour?
Golf: Would You Rather Be the LONGEST or STRAIGHTEST Driver on the PGA Tour?
Ken Jee
49 Data Science Fundamentals: Linear Regression
Data Science Fundamentals: Linear Regression
Ken Jee
50 How YOU Can Land a Sports Analytics Job
How YOU Can Land a Sports Analytics Job
Ken Jee
51 The 5 Stages of Data Science Adoption
The 5 Stages of Data Science Adoption
Ken Jee
52 Math Needed for Mastering Data Science
Math Needed for Mastering Data Science
Ken Jee
53 5 Sports Analytics Books to Get You Started
5 Sports Analytics Books to Get You Started
Ken Jee
54 3 Reasons You Should NOT Become a Data Scientist
3 Reasons You Should NOT Become a Data Scientist
Ken Jee
55 Collision Course: Sports Betting + Data Science
Collision Course: Sports Betting + Data Science
Ken Jee
56 How to Scrape NBA Data Using the nba_api Python Module
How to Scrape NBA Data Using the nba_api Python Module
Ken Jee
57 5 Data Science Resolutions for 2020
5 Data Science Resolutions for 2020
Ken Jee
58 The Data Science Interview: What to Expect
The Data Science Interview: What to Expect
Ken Jee
59 The 9 Books That Changed My Perspective in 2019
The 9 Books That Changed My Perspective in 2019
Ken Jee
60 Questions You Should Ask Your Data Science Interviewers
Questions You Should Ask Your Data Science Interviewers
Ken Jee

This video teaches viewers how to use the Twitterscraper Python module to scrape Twitter data and transform it into a pandas DataFrame for analysis. The module is useful for retrieving tweets without needing a Twitter API key, and the video demonstrates its functionality by scraping tweets related to the Notre Dame fire.

Key Takeaways
  1. Install the Twitterscraper module using pip
  2. Import the Twitterscraper module and pandas library
  3. Set query parameters such as begin date, end date, limit, and language
  4. Use the query_tweets function to retrieve tweets
  5. Transform the tweet data into a pandas DataFrame
  6. Remove duplicates and filter the data as needed
  7. Perform sentiment analysis or other text-based analysis on the tweet data
💡 The Twitterscraper module allows users to retrieve Twitter data without needing a Twitter API key, making it a useful tool for social media analysis and data science applications.

Related AI Lessons

Up next
‘ENOUGH IS ENOUGH’: Lebanon is STANDING UP to Iran, expert says
Fox Business
Watch →