本文整理匯總了Python中scrapy.exporters.CsvItemExporter方法的典型用法代碼示例。如果您正苦於以下問題:Python exporters.CsvItemExporter方法的具體用法?Python exporters.CsvItemExporter怎麽用?Python exporters.CsvItemExporter使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類scrapy.exporters
的用法示例。
在下文中一共展示了exporters.CsvItemExporter方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: process_item
# 需要導入模塊: from scrapy import exporters [as 別名]
# 或者: from scrapy.exporters import CsvItemExporter [as 別名]
def process_item(self, item, spider):
if spider.name != '':
asin = item.get('asin', None)
if asin:
self.counter += 1
if self.counter == 10000:
self.exporter.finish_exporting()
file = self.files.pop(spider)
file.close()
self.file_count += 1
file = open('amazon_products_%s.csv' % (self.file_count),'w+b')
self.files[spider] = file
self.export_fields = ['title', 'asin', 'category', 'rank', 'new_price1', 'new_price2']
self.exporter = CsvItemExporter(file, fields_to_export=self.export_fields)
self.exporter.start_exporting()
self.counter = 0
print self.counter, '*'*50
self.exporter.export_item(item)
return item
示例2: spider_opened
# 需要導入模塊: from scrapy import exporters [as 別名]
# 或者: from scrapy.exporters import CsvItemExporter [as 別名]
def spider_opened(self, spider):
fields_to_export = ['mailingList', 'emailId',
'senderName', 'senderEmail',
'timestampSent', 'timestampReceived',
'subject', 'url', 'replyto']
fields_to_export = [f for f in fields_to_export if f not in spider.drop_fields]
if not os.path.exists('data'):
os.makedirs('data')
if len(spider.scraping_lists) == 1:
dest_file_path = 'data/{}ByEmail.csv'.format(spider.scraping_lists[0])
fields_to_export.remove('mailingList')
else:
dest_file_path = 'data/{}ByEmail.csv'.format(spider.name)
dest_file = open(dest_file_path, 'wb')
self.exporter = CsvItemExporter(dest_file)
self.files[spider] = dest_file
self.exporter.fields_to_export = fields_to_export
self.exporter.start_exporting()
示例3: spider_opened
# 需要導入模塊: from scrapy import exporters [as 別名]
# 或者: from scrapy.exporters import CsvItemExporter [as 別名]
def spider_opened(self, spider):
files = [
('bos', 'bos.csv'),
('vitimas', 'vitimas.csv'),
('naturezas', 'naturezas-envolvidas.csv'),
]
for key, fname in files:
file = open(join(spider.target_dir, fname), 'w+b')
self.files.append(file)
self.exporters[key] = CsvItemExporter(file)
self.exporters[key].start_exporting()
示例4: spider_opened
# 需要導入模塊: from scrapy import exporters [as 別名]
# 或者: from scrapy.exporters import CsvItemExporter [as 別名]
def spider_opened(self, spider):
"""
????????????
:param spider:
:return:
"""
print time.strftime("%Y-%m-%d %H:%M:%S"), 'Pipeline Signals: spider_opened'
file_csv = open('%s_items.csv' % spider.name, 'w+b')
self.files[spider] = file_csv
self.exporter = CsvItemExporter(file_csv)
self.exporter.start_exporting()
示例5: spider_opened
# 需要導入模塊: from scrapy import exporters [as 別名]
# 或者: from scrapy.exporters import CsvItemExporter [as 別名]
def spider_opened(self, spider):
file_csv = open('%s_items.csv' % spider.name, 'w+b')
self.files[spider] = file_csv
self.exporter = CsvItemExporter(file_csv)
self.exporter.start_exporting()
示例6: __init__
# 需要導入模塊: from scrapy import exporters [as 別名]
# 或者: from scrapy.exporters import CsvItemExporter [as 別名]
def __init__(self):
self.file = open("quotedata.csv", 'wb')
self.exporter = CsvItemExporter(self.file, unicode)
self.exporter.start_exporting()
示例7: __init__
# 需要導入模塊: from scrapy import exporters [as 別名]
# 或者: from scrapy.exporters import CsvItemExporter [as 別名]
def __init__(self):
self.file = open("booksdata.csv", 'wb')
self.exporter = CsvItemExporter(self.file, unicode)
self.exporter.start_exporting()
示例8: spider_opened
# 需要導入模塊: from scrapy import exporters [as 別名]
# 或者: from scrapy.exporters import CsvItemExporter [as 別名]
def spider_opened(self, spider):
file = open('jd_{}.csv'.format(self.file_count), 'w+b')
self.files[spider] = file
self.exporter = CsvItemExporter(file)
self.exporter.start_exporting()
示例9: spider_opened
# 需要導入模塊: from scrapy import exporters [as 別名]
# 或者: from scrapy.exporters import CsvItemExporter [as 別名]
def spider_opened(self, spider):
if spider.name != '':
file = open('amazon_products_%s.csv' % (self.file_count),'w+b')
self.files[spider] = file
self.export_fields = ['title', 'asin', 'category', 'rank', 'new_price1', 'new_price2']
self.exporter = CsvItemExporter(file, fields_to_export=self.export_fields)
self.exporter.start_exporting()
示例10: spider_opened
# 需要導入模塊: from scrapy import exporters [as 別名]
# 或者: from scrapy.exporters import CsvItemExporter [as 別名]
def spider_opened(self, spider):
spider_name = re.sub('-.+?$', '', spider.name)
self.filename = spider_name + ".csv"
file = open('output/' + self.filename, 'w+b', 0)
exporter = CsvItemExporter(file)
EXPORT_FIELDS = [
'BrandTitle',
'BrandPictureLink',
'BrandDescription',
'CategoryTitle',
'CategoryPictureLink',
'CategoryDescription',
'ProductTitle',
'ProductPictureLink',
'ProductThcContent',
'ProductCbdContent',
'ProductDescription',
'ProductURL',
]
exporter.fields_to_export = EXPORT_FIELDS
exporter.start_exporting()
self.exporters['Result'] = exporter