我想从twitter
检索推文并将其保存在CSV
文件中。我使用以下代码,但未显示任何结果,也没有错误。怎么了?
import tweepy
import csv
consumer_key = 'xxx'
consumer_secret = 'xxx'
access_token = 'xxx'
access_token_secret = 'xxx'
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
api = tweepy.API(auth)
search = raw_input('Search :> ')
csvFile = open('result.csv', 'a')
csvWriter = csv.writer(csvFile)
for tweet in tweepy.Cursor(api.search,
q='{}'.format(search),
since = "2018-07-1",
until = "2018-07-4",
lang = "ar").items():
csvWriter.writerow([tweet.created_at, tweet.text.encode('utf-8')])
print tweet.created_at, tweet.text
csvFile.close()