从批处理文件运行scrapy spider会导致每行之间出现空白行

时间:2019-07-15 13:06:30

标签: python scrapy anaconda

如果我从PyChram或Anaconda中运行scrapy,它会正常工作,csv输出也是如此。但是,如果我通过批处理文件运行同一蜘蛛,则输出在行之间会有其他空行。

批处理文件:

echo off
set root= <anaconda_dir>
call %root%\Scripts\activate.bat   %root%
cd <python file path>
python spider.py
pause

用于保存csv文件的管道:

from scrapy.exporters import CsvItemExporter

class CsvPipeline(object):

    def __init__(self):
        self.file = open(<path>, 'wb')
        self.exporter = CsvItemExporter(self.file, "utf-8")
        self.exporter.start_exporting()

    def close_spider(self, spider):
        self.exporter.finish_exporting()
        self.file.close()

    def process_item(self, item, spider):
        self.exporter.export_item(item)
        return item

这变得越来越混乱,我在另一台计算机上运行了代码,而csv文件中没有空行。输出正常。


更新:由于它在其他计算机上运行良好,因此我决定重新安装Anaconda。重新安装后,输出中不再有空行。

0 个答案:

没有答案