Last active
May 28, 2021 14:12
-
-
Save revox/3eb8136d61956a7ed8e7 to your computer and use it in GitHub Desktop.
Use tweepy to write some tweet info into a CSV file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time | |
import tweepy | |
import csv | |
# == OAuth Authentication == | |
# The consumer keys can be found on your application's Details | |
# page located at https://dev.twitter.com/apps (under "OAuth settings") | |
consumer_key="your key" | |
consumer_secret="your secret" | |
# After the step above, you will be redirected to your app's page. | |
# Create an access token under the the "Your access token" section | |
access_token="your token" | |
access_token_secret="your token" | |
# OAuth process, using the keys and tokens | |
auth = tweepy.OAuthHandler(consumer_key, consumer_secret) | |
auth.set_access_token(access_token, access_token_secret) | |
# Creation of the actual interface, using authentication | |
api = tweepy.API(auth) | |
results = api.search('#fracking', count=100) | |
csvfile = open('my_scraped_tweets.csv','wb') | |
csvwriter = csv.writer(csvfile) | |
for item in results: | |
# write out the user, the tweet and their follower count into a file | |
# the unicode bits are required to write non ASCII language bits into the file | |
csvwriter.writerow([unicode(item.user.screen_name).encode("utf-8"),unicode(item.text).encode("utf-8"),item.user.followers_count]) | |
# time.sleep(1) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
when I try this I get the following error:
csvwriter.writerow([unicode(item.user.screen_name).encode("utf-8"),unicode(item.text).encode("utf-8"),item.user.followers_count])
NameError: name 'unicode' is not defined