From eb91cb8ea2c0fa3cd852a50fb45482d7fd887dd5 Mon Sep 17 00:00:00 2001 From: Bernardas Date: Mon, 3 Oct 2016 20:31:41 +0000 Subject: [PATCH 1/2] fix JsonWriterPipeline example --- docs/topics/item-pipeline.rst | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/docs/topics/item-pipeline.rst b/docs/topics/item-pipeline.rst index 6b43fe258..11b56f1c4 100644 --- a/docs/topics/item-pipeline.rst +++ b/docs/topics/item-pipeline.rst @@ -106,9 +106,12 @@ format:: class JsonWriterPipeline(object): - def __init__(self): + def open_spider(self, spider): self.file = open('items.jl', 'wb') + def close_spider(self, spider): + self.file.close() + def process_item(self, item, spider): line = json.dumps(dict(item)) + "\n" self.file.write(line) From dfba151f59366f461ceb0d0ea1b6be6c89dc6d10 Mon Sep 17 00:00:00 2001 From: Bernardas Date: Wed, 5 Oct 2016 16:35:23 +0000 Subject: [PATCH 2/2] Remove unnecessary note for the JsonWriterPipeline example --- docs/topics/item-pipeline.rst | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/docs/topics/item-pipeline.rst b/docs/topics/item-pipeline.rst index 11b56f1c4..8c7aa361f 100644 --- a/docs/topics/item-pipeline.rst +++ b/docs/topics/item-pipeline.rst @@ -129,14 +129,7 @@ MongoDB address and database name are specified in Scrapy settings; MongoDB collection is named after item class. The main point of this example is to show how to use :meth:`from_crawler` -method and how to clean up the resources properly. - -.. note:: - - Previous example (JsonWriterPipeline) doesn't clean up resources properly. - Fixing it is left as an exercise for the reader. - -:: +method and how to clean up the resources properly.:: import pymongo