我想收到包含' love'的推文。和/或' #hate'使用Python Tweepy。但是使用我当前的代码如下所示,它只返回第一个词(即' love')。我一直在尝试调试和阅读Tweepy / Twitter文档几天无济于事。请指教。
import tweepy
import time
ckey = ""
csecret = ""
atoken = ""
asecret = ""
OAUTH_KEYS = {'consumer_key':ckey, 'consumer_secret':csecret,
'access_token_key':atoken, 'access_token_secret':asecret}
auth = tweepy.OAuthHandler(OAUTH_KEYS['consumer_key'], OAUTH_KEYS['consumer_secret'])
api = tweepy.API(auth)
for tweet in tweepy.Cursor(api.search, q=('love' or '#hate'), since='2014-09-15', until='2014-09-16').items(500):
try:
print "Tweet created:", tweet.created_at
print "Tweet:", tweet.text.encode('utf8')
counter += 1
except IOError:
time.sleep(60)
continue
答案 0 :(得分:3)
通过查看Twitter API文档,'或'应该大写,并且应该在单引号内:
q =('爱或#恨#39;)