當前位置: 首頁>>代碼示例>>Python>>正文


Python exporters.CsvItemExporter方法代碼示例

本文整理匯總了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 
開發者ID:parul1931,項目名稱:amazon,代碼行數:24,代碼來源:pipelines.py

示例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() 
開發者ID:gaalcaras,項目名稱:mailingListScraper,代碼行數:26,代碼來源:pipelines.py

示例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() 
開發者ID:eltermann,項目名稱:ssp-transparencia,代碼行數:13,代碼來源:pipelines.py

示例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() 
開發者ID:zhanghe06,項目名稱:scrapy_project,代碼行數:13,代碼來源:signals.py

示例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() 
開發者ID:zhanghe06,項目名稱:scrapy_project,代碼行數:7,代碼來源:exporter_csv.py

示例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() 
開發者ID:zseta,項目名稱:scrapyfundamentals,代碼行數:6,代碼來源:pipelines.py

示例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() 
開發者ID:zseta,項目名稱:scrapyfundamentals,代碼行數:6,代碼來源:pipelines.py

示例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() 
開發者ID:poluo,項目名稱:Spider,代碼行數:7,代碼來源:pipelines.py

示例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() 
開發者ID:parul1931,項目名稱:amazon,代碼行數:9,代碼來源:pipelines.py

示例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 
開發者ID:gangabass,項目名稱:weedmaps,代碼行數:29,代碼來源:pipelines.py


注:本文中的scrapy.exporters.CsvItemExporter方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。