Scrapy python csv output has blank lines between each row

前端 未结 2 394
自闭症患者
自闭症患者 2021-01-02 23:39

I am getting unwanted blank lines between each row of scrapy output in the resulting csv output file.

I have moved from python2 to python 3, and I use Windows 10. I

2条回答
  •  离开以前
    2021-01-03 00:16

    The b in w+b is most probably part of the problem as this will make the file being considered a binary file and so linebreaks are written as is.

    So first step is to remove the b. And then by adding U you can also activate the Universal Newline support ( see: https://docs.python.org/3/glossary.html#term-universal-newlines )

    So the line in question should look like:

    file = open('%s_items.csv' % spider.name, 'Uw+')
    

提交回复
热议问题