本文整理匯總了Python中catalog.Catalog.to_csv方法的典型用法代碼示例。如果您正苦於以下問題:Python Catalog.to_csv方法的具體用法?Python Catalog.to_csv怎麽用?Python Catalog.to_csv使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類catalog.Catalog
的用法示例。
在下文中一共展示了Catalog.to_csv方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: Extractor
# 需要導入模塊: from catalog import Catalog [as 別名]
# 或者: from catalog.Catalog import to_csv [as 別名]
class Extractor(object):
__metaclass__ = ABCMeta
name = 'Course Extractor'
def __init__(self, spider=None, input_directory='raw_output'):
"""
:param spider: spider
:type spider: CourseSpider
:return:
"""
if spider is None:
self.input_directory = input_directory
self.catalog = Catalog()
self.name = self.input_directory
self.timestamp = date.today()
else:
self.input_directory = spider.get_raw_output()
self.catalog = Catalog()
self.name = spider.get_name()
self.timestamp = spider.get_timestamp()
def set_input_directory(self, directory):
# set the directory of raw html files
self.input_directory = directory
@abstractmethod
def extract_each(self, filename):
"""
:param filename:
:return: extracted catalog
:rtype: Catalog
"""
pass
def extract_all(self):
file_list = [self.input_directory+'/' + f for f in os.listdir(self.input_directory)]
num_files = len(file_list)
print '[INFO] start extracting from %s' % self.name
print '[INFO] total files: %d' % num_files
for each in file_list:
print '[INFO] processing file: %s, %d remaining' % (each, num_files)
self.catalog.append_catalog(self.extract_each(each))
num_files -= 1
print '[SUMMARY] finished extraction'
def to_csv(self):
print '[INFO] saving catalog to file'
self.catalog.to_csv(self.name+'__'+str(self.timestamp), sep=',')
def print_result(self):
print self.catalog