我正在使用scrapy并将从网页获取的数据写入CSV文件
我的pipeline
代码:
def __init__(self):
self.file_name = csv.writer(open('example.csv', 'wb'))
self.file_name.writerow(['Title', 'Release Date','Director'])
def process_item(self, item, spider):
self.file_name.writerow([item['Title'].encode('utf-8'),
item['Release Date'].encode('utf-8'),
item['Director'].encode('utf-8'),
])
return item
我在 CSV 文件中的输出格式是:
Title,Release Date,Director
And Now For Something Completely Different,1971,Ian MacNaughton
Monty Python And The Holy Grail,1975,Terry Gilliam and Terry Jones
Monty Python's Life Of Brian,1979,Terry Jones
.....
但是是否可以将title
其值写入一列,Release date
将其值写入下一列,Director
并将其值写入下一列(因为 CSV 是逗号分隔值),格式如下所示。
Title, Release Date, Director
And Now For Something Completely Different, 1971, Ian MacNaughton
Monty Python And The Holy Grail, 1975, Terry Gilliam and Terry Jones
Monty Python's Life Of Brian, 1979, Terry Jones
任何帮助,将不胜感激。提前致谢。