Collecting Twitter Data using Python

Image for post
Image for post
Photo by Brett Jordan on Unsplash
import tweepy as twimport pandas as pd
api_key = 'YOUR_API_KEY'api_secret_key = 'YOUR_API_SECRET_KEY'access_token = 'YOUR_ACCESS_TOKEN'access_token_secret = 'YOUR_ACCESS_TOKEN_SECRET'auth = tw.OAuthHandler(api_key, api_secret_key)auth.set_access_token(access_token, access_token_secret)api = tw.API(auth, wait_on_rate_limit=True, wait_on_rate_limit_notify=True)
key_words = "your keyword"search_result = tw.Cursor(, q=key_words, lang="id", truncated=True).items(10)crawling_result = [api.get_status(, tweet_mode="extended") for data in search_result]tweet_list = [[status.user.screen_name, status.full_text, status.retweet_count, status.favorite_count, status.geo, status.source, status.user.verified,,,, status.user.statuses_count, status.user.friends_count, status.user.followers_count, status.user.location] for status in crawling_result]
tweet_df = pd.DataFrame(data = tweet_list, columns=["username", "tweet", "retweet_count", "like_count", "location", "device", "verified_status", "acc_creation_date","no_profile_pic", "no_bio", "tweets_count", "followings_count", "followers_count", "user_location"])tweet_df
tweet_df.to_csv(r'Data_Collection_Result.csv', index=False)

〖A data geek 📊〗〖Life-long learner〗〖ESFP-T〗〖✨ŸØⱠØ✨〗

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store