我正在尝试从 Twitter 收集电影评论。然而,我只收到 76 条推文。我试图排除 tweeterror 但这没有帮助。这是我的代码:
import tweepy
import time
import cPickle as pickle
auth = tweepy.OAuthHandler(**hidden**)
auth.set_access_token(**hidden**)
api = tweepy.API(auth)
def limit_handled(cursor):
while True:
try:
yield cursor.next()
"I am awake..."
except tweepy.error:
print "going to sleep..."
time.sleep(15 * 60)
except StopIteration:
break
query = '#moviereview -filter:links'
max_tweets = 1000000
searched_tweets = [status.text for status in limit_handled(tweepy.Cursor(api.search, q=query).items(max_tweets))]
with open("twitter_reviews.pkl","wb") as f:
pickle.dump(searched_tweets,f,-1)
print len(searched_tweets)
最佳答案
尝试修改您的查询参数,根据您的代码,这不是过滤掉进一步结果的原因。
查询:
'#moviereview -filter:links'
提供 78 个结果(并且还在增加)
查询:
'#moviereview'
提供 1713 个结果(并且还在增加)
查询:
'#moviereview Filter:links'
提供 4534 个结果(并且还在增加)
正如 @Ethan 提到的 + Twitters API 文档 ( https://dev.twitter.com/rest/public/search )
The Twitter Search API searches against a sampling of recent Tweets published in the past 7 days.
关于python - Tweepy 仅返回 76 条推文,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37399639/