本文整理汇总了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