scrapy.exporters.CsvItemExporter - python examples

Here are the examples of the python api scrapy.exporters.CsvItemExporter taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

4 Examples 7

3 View Complete Implementation : pipelines.py
Copyright GNU General Public License v3.0
Author : datawizard1337
    def open_spider(self, spider):
        url_chunk = spider.url_chunk
        chunk = url_chunk.split(".")[0].split("_")[-1]
        try:
            self.fileobj = open(os.getcwd() +"\\chunks\\output_" + chunk + ".csv", "ab")
        except:
            self.fileobj = open(os.getcwd() +"\\chunks\\output_" + chunk + ".csv", "wb")
        self.exporter = CsvItemExporter(self.fileobj, encoding='utf-8', delimiter="\t")
        self.exporter.fields_to_export = ["ID", "dl_rank", "dl_slot", "error", "redirect", "start_page", "satle", "keywords", "description", "text", "timestamp", "url"]
        self.exporter.start_exporting()

3 View Complete Implementation : pipelines.py
Copyright GNU General Public License v3.0
Author : datawizard1337
    def open_spider(self, spider):
        url_chunk = spider.url_chunk
        chunk = url_chunk.split(".")[0].split("_")[-1]
        try:
            self.fileobj = open(os.getcwd() +"\\chunks\\output_" + chunk + ".csv", "ab")
        except:
            self.fileobj = open(os.getcwd() +"\\chunks\\output_" + chunk + ".csv", "wb")
        self.exporter = CsvItemExporter(self.fileobj, encoding='utf-8', delimiter="\t")
        self.exporter.start_exporting()

3 View Complete Implementation : pipelines.py
Copyright Apache License 2.0
Author : xingag
    def open_spider(self, spider):
        self.csv_file = open('weixin.csv', 'wb')
        self.csv_exporter = CsvItemExporter(self.csv_file)

        # 开始写入数据
        self.csv_exporter.start_exporting()

0 View Complete Implementation : pipelines.py
Copyright GNU General Public License v3.0
Author : gaalcaras
    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()