之前我使用过以下脚本,但现在它无效了。我没有看到任何推文在我的终端上打印(如第38行所示),也没有任何推文存储在我的csv中。我不是什么问题。
import tweepy
import csv
import time
access_token = "xxxxxxxxxx"
access_token_secret = "xxxxxxxxxx"
consumer_key = "xxxxxxxxxx"
consumer_secret = "xxxxxxxxxx"
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
api = tweepy.API(auth)
print "Starting search..."
#
# Open/Create a file to append data
csvFile = open('somesearch.csv', 'a')
#Use csv Writer
csvWriter = csv.writer(csvFile)
searchTerms = ["#Xfactor", "#Yfactor"]
tweets= tweepy.Cursor(api.search,q=[searchTerms], \
since="2015-10-18",
until="2015-10-23",
include_entities=True).items(999999999)
#csvWriter.writerow([tweet.created_at, tweet.id_str, tweet.screen_name, tweet.user_id, tweet.coordinates, tweet.place, tweet.text.encode('utf-8'), tweet.retweet_count, tweet.favorite_count])
#tweet.in_reply_to_user_id_str, tweet.in_reply_to_screen_name, tweet.in_reply_to_status_id_str, tweet.retweeted, tweet.truncated, tweet.source
while True:
try:
for tweet in tweets:
print tweet.created_at, tweet.text.encode('utf-8')
csvWriter.writerow([tweet.created_at, tweet.id_str, tweet.author.name.encode('utf-8'), tweet.author.screen_name.encode('utf-8'),
tweet.user.location.encode('utf-8'), tweet.coordinates, tweet.text.encode('utf-8'), tweet.retweet_count, tweet.favorite_count])
except tweepy.TweepError:
time.sleep(60 * 15)
continue
except StopIteration:
break
print "Done!"
答案 0 :(得分:0)
问题出在这一行:
void init () override {
cout << "I'm the child" << endl;
};
您所做的是创建一个包含列表的列表。看看这段代码:
tweets= tweepy.Cursor(api.search,q=[searchTerms],
您要搜索的内容不是searchTerms = ["#Xfactor", "#Yfactor"]
q=[searchTerms]
print(searchTerms)
>>> ['#Xfactor', '#Yfactor']
print(type(q))
>>> [['#Xfactor', '#Yfactor']]
,而是在搜索该列表。
所以现在你对感兴趣的推文必须包含文字searchTerms
。要解决该问题,请将['#Xfactor', '#Yfactor']
更改为:
q