各位好,小弟之前发问的问题,经过各位大大前辈的指点,
已经解决了,但是小弟今天又遇到一个小问题,写完pipelines后,
一执行,就会出现KeyError,参考
http://www.hackhowtofaq.com/blog/web-scraping-with-scrapy/,
写出我的pipelines,以下是我的程式码
pipelines.py:
import csv
class testPipeline(object):
def__init__(self):
self.myCSV = csv.writer(open('birds.csv', 'wb'))
self.myCSV.writerow(['title', 'birdName','count'])
def process_item(self, item,spider):
self.myCSV.writerow([item['title'].encode('utf-8'),
item['birdName'].encode('utf-8'),
item['count'].encode('utf-8')])
return item
一直出现这两个错误
1. File "D:\python27\allentest\allentest\pipelines.py", line 17, in
process_item
self.myCSV.writerow([item['title'].encode('utf-8'),
exceptions.AttributeError: 'list' object has no attribute 'encode'
2. File "D:\python27\lib\site-packages\scrapy\item.py", line 50, in __getitem__
return self._values[key]
exceptions.KeyError: 'title'
可是我参照范例写出来的,请问我该怎样修改?