我发现这个Python代码通过自定义搜索查询刮叽叽喳喳:如何使用python刮板将结果保存到csv?
https://github.com/tomkdickinson/Twitter-Search-API-Python/blob/master/TwitterScraper.py
我想从这个代码的结果存储到一个CSV文件。
我试图在内部围绕线245添加CSV作家循环,打印出的鸣叫按我的搜索查询,但CSV文件的结果为空白
def save_tweets(self, tweets):
"""
Just prints out tweets
:return: True always
"""
for tweet in tweets:
# Lets add a counter so we only collect a max number of tweets
self.counter += 1
if tweet['created_at'] is not None:
t = datetime.datetime.fromtimestamp((tweet['created_at']/1000))
fmt = "%Y-%m-%d %H:%M:%S"
myCsvRow = log.info("%i [%s] - %s" % (self.counter, t.strftime(fmt), tweet['text']))
fd = open('document.csv','a')
fd.write(myCsvRow)
fd.close()
return True
另外,有一个在评论代码在170行左右提到:
@abstractmethod
def save_tweets(self, tweets):
"""
An abstract method that's called with a list of tweets.
When implementing this class, you can do whatever you want with these tweets.
"""
如何使用此类保存推文?
感谢您的答案和提示! –