Ohio Chat Rooms

Thanks for visiting Ohio Chat Club. Here you can find current news and events around Ohio. Chat with people form Ohio live, online, free. Join the Ohio chat room today. Ohio chat club rooms online community is for Ohio singles, couples & teens online. Download the Free Android Ohio chat rooms app. Share YouTube & Giphy in live chat with friends, upload files, custom avatars & pictures from Ohio.

Crawl Twitter Data using 30 Lines of Python Code

Dea Venditama
Photo by Benjamin Balázs on Unsplash

in text analysis which using twitter data, crawling is an important thing to do. There are many ways for us to do that, to crawl twitter data we can use official twitter API and many programming languages. Python 3 comes with many useful libraries which makes easier for us to do a lot of things with it. Tweepy is one of the Python 3 libraries which can be used to crawl twitter data. I assume the reader has the basic knowledge in Python so I didn’t explain it from basic and I will be focused on Tweepy things.

If you are new to Tweepy and want comprehensive knowledge about it, you can go to http://docs.tweepy.org/en/latest/getting_started.html and read the Tweepy documentation. After that, you must install Tweepy using pip, go to http://docs.tweepy.org/en/latest/install.html for the installation steps.

Here is the full Python code

now I will explain about the codes above,
first of all, of course, we must import the Tweepy library to use it.

save your consumer key, consumer secret, access token and access secret on a variable, its make easier for us if we want to change the keys.

consumer_key = ‘change with your consumer key’
consumer_secret = ‘change with your consumer secret’
access_token = ‘change with your access token’
access_secret = ‘change with your access secret’

tweetsPerQry is the number of results that we retrieve per request, maxTweets is the maximum number of tweets that we want to retrieve and the hashtag variable is a keyword that we want to search. I use mencatatindonesia hashtags as a search query, mencatatindonesia is a tagline of Indonesia 2020 census which held every 10 years.

Line 11–13 are used for twitter authentication, in line 13 there are two parameters besides authentication, wait_on_rate_limit and wait_on_rate_limit_notify are used to call the auto-sleep function in Tweepy when hits the rate limit of Twitter API.

we use a while loop to request all available tweets in #MencatatIndonesia hashtag. If Statements in Line 17–20 is used to request tweet data, when maxId is less than 1, the programs run search query from the latest tweet and then save the last id to become maxId, so the program can do a request again from the latest tweet based on maxId.

Line 26 is used for iterate tweets data that we get from every request, for every tweet we print out the text content. If there are no more tweets that can be found in a request, it will break our Python Twitter Crawler application and print out “Tweet habis” (Tweet habis means There are no more tweets in Bahasa languages)right before its break.

this is my command line screenshot of our twitterCrawler.py. There are 1082 available tweets contain #mencatatindonesia hashtag. If you want to print the number of tweets, you can print the tweetCount variable which has existed in our programs.

That’s all for this tutorial, Thank You…..

Recent Articles

How do you guys pronounce it? Sciotoh or sciotuh? : Columbus

level 1The only way to pronounce it is with a ‘tuh’...unless you’re Siri or a Garmin...

Prominent Civil Rights Leader Tells Ohio Legislators: Focus on Addressing Racism, Poverty

By Susan Tebben A prominent civil rights leader and anti-poverty advocate said Friday Ohio legislators need to be focused on passing bills against racism, and refocusing...

School Nurses on Reopening Plans, Lack of Staffing, Virtual Health Care & More

By Susan Tebben In her nearly 40 years as a school nurse, Patricia Gunter has had to prepare for diseases like swine flu, H1N1, West Nile...

Please be on the lookout. : Columbus

Hey Everyone... This is my brother Garrett. He went missing last night, from what I know he is hitch hiking to Toronto. He is...

Helping the global pharmaceutical supply chain. | by Natalia Pedroza | Aug, 2020

Because finding a vaccine is just not enough.It’s great to see how suddenly pharmaceutical companies, once competing with each other, are now in a...

Related Stories

Leave A Reply

Please enter your comment!
Please enter your name here

Stay on op - Ge the daily news in your inbox