各位好,小弟之前發問的問題,經過各位大大前輩的指點,
已經解決了,但是小弟今天又遇到一個小問題,寫完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'
可是我參照範例寫出來的,請問我該怎樣修改?