原文链接:https://blog.csdn.net/hongchen37/article/details/80907743

使用scrapy命令行将数据保存为csv文件时,发现csv多空行。

scrapy输出csv文件数据多空行问题解决

scrapy输出csv文件数据多空行问题解决

百度https://stackoverflow.com/questions/39477662/scrapy-csv-file-has-uniform-empty-rows/43394566#43394566

查看源码scrapy.exporters.CsvItemExporter,在io.TextIOWrapper加入参数newline='',问题就解决啦。

  1. class CsvItemExporter(BaseItemExporter):
  2. def __init__(self, file, include_headers_line=True, join_multivalued=',', **kwargs):
  3. self._configure(kwargs, dont_fail=True)
  4. if not self.encoding:
  5. self.encoding = 'utf-8'
  6. self.include_headers_line = include_headers_line
  7. self.stream = io.TextIOWrapper(
  8. file,
  9. newline='',
  10. line_buffering=False,
  11. write_through=True,
  12. encoding=self.encoding
  13. ) if six.PY3 else file
  14. self.csv_writer = csv.writer(self.stream, **kwargs)
  15. self._headers_not_written = True
  16. ...

相关文章:

  • 2022-12-23
  • 2021-08-01
  • 2021-11-10
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-10-25
  • 2022-12-23
猜你喜欢
  • 2021-08-04
  • 2021-12-02
  • 2022-12-23
  • 2021-06-22
  • 2021-09-17
  • 2021-09-19
  • 2021-03-30
相关资源
相似解决方案