twitter python代码仅执行有限数量的推文和术语

时间:2019-03-26 23:55:23

标签: python-3.x

我正在以下代码下运行,以获取有限数量的推文,但代码始终失败。

# Create the api endpoint

auth = tweepy.OAuthHandler(ckey, csecret)
api = tweepy.API(auth)

# Mention the maximum number of tweets that you want to be extracted.

maximum_number_of_tweets_to_be_extracted = \
int(input('10- '))

# Mention the hashtag that you want to look out for

hashtag = input('Roger- ')

for tweet in tweepy.Cursor(api.search, q='#' + hashtag,
rpp=100).items(maximum_number_of_tweets_to_be_extracted):
    with open('tweets_with_hashtag_' + hashtag + '.txt', 'a') as \
the_file:
the_file.write(str(tweet.text.encode('utf-8')) + '\n')

print ('Extracted ' + str(maximum_number_of_tweets_to_be_extracted) \
+ ' tweets with hashtag #' + hashtag)

删除文件语法,我认为问题出在哪里

0 个答案:

没有答案