我發現這個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.
"""
如何使用此類保存推文?
感謝您的答案和提示! –