我尝试按照how to implement nested item in scrapy?中的建议嵌套项目但是我收到以下错误消息:
i[a]
我该怎么迭代?我已经尝试将以下内容插入到Sons.Item类中:
Traceback (most recent call last):
File "/home/x/workspace/Crawler/venv/local/lib/python2.7/site-packages/scrapy/utils/defer.py", line 102, in iter_errback
yield next(it)
File "/home/x/workspace/Crawler/venv/local/lib/python2.7/site-packages/scrapy/spidermiddlewares/offsite.py", line 29, in process_spider_output
for x in result:
File "/home/x/workspace/Crawler/venv/local/lib/python2.7/site-packages/scrapy/spidermiddlewares/referer.py", line 22, in <genexpr>
return (_set_referer(r) for r in result or ())
File "/home/x/workspace/Crawler/venv/local/lib/python2.7/site-packages/scrapy/spidermiddlewares/urllength.py", line 37, in <genexpr>
return (r for r in result or () if _filter(r))
File "/home/x/workspace/Crawler/venv/local/lib/python2.7/site-packages/scrapy/spidermiddlewares/depth.py", line 58, in <genexpr>
return (r for r in result or () if _filter(r))
File "/home/x/workspace/Crawler/test.py", line 53, in parse
s1['grandsons'] = [dict(gs1), dict(gs2)]
TypeError: iteration over non-sequence
但它没有帮助。我在这做错了什么?谢谢。 :)
完整的代码是:
def __iter__(self):
return iter(self.grandsons)