我想要在过去的几天内搜索推特,找出2-3个关键词,但我不知道如何一次搜索多个关键词。虽然有其他方法实现这一需求,但我使用了 tweepy.cursor 的简短代码。可是,我不知道如何一次搜索多个查询词(例如,我想要同时搜索 #superbowl / superbowl / super bowl)。我尝试了几种方法,但下面的代码好像只能返回AND逻辑语句。我还没有找到任何有用的文档说明。希望能得到帮助!
import tweepy
from datetime import datetime,timedelta
import csv
access_token = "..."
access_token_secret = "..."
consumer_key = "..."
consumer_secret = "..."
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
api = tweepy.API(auth)
csvFile = open('output.csv', 'a')
csvWriter = csv.writer(csvFile)
search_terms = 'superbowl ', 'super bowl ', '#superbowl'
for status in tweepy.Cursor(api.search,
q=search_term,
since='2017-02-16', until='2017-02-17',
count=10,
result_type='recent',
include_entities=True,
monitor_rate_limit=True,
wait_on_rate_limit=True,
lang="en").items():
eastern_time = status.created_at - timedelta(5)
edt_time = eastern_time.strftime('%Y-%m-%d %H:%M')
csvWriter.writerow([status.created_at, status.user.screen_name.encode('utf8'), status.text.encode('utf-8')])
csvFile.close()
search_terms = ('superbowl OR super bowl OR #superbowl')
。 - Kees