繼上次發問pipelines的問題後,已經自行解決keyerror的問題,
這次是無法寫入CSV檔,明明執行的時候都沒出現錯誤訊息,但就是寫不進去
CSV檔,附上程式碼
pipelines.py
import csv
from myproject.items import BirdTitle,BirdName,BirdCount
class myPipeline(object):
def __init__(self):
self.myCSV = csv.writer(open('birds.csv','wb'))
self.myCSV.writerow(['title','birdname','count'])
def process_item(self, item,spider):
titles=[]
names=[]
counts=[]
for title in item:
if isinstance(item, BirdTitle):
for title in item['title']:
titles.append(title)
return titles
for name in item:
if isinstance(item, BirdName):
for name in item['birdName']:
names.append(name)
return names
for count in item:
if isinstance(item,BirdCount):
for count in item['count']:
counts.append(count)
return counts
for a, b,c in zip(titles,names,counts):
self.myCSV.writerow([a, b,c])
return item
請問我該如何解決?