Monkey patch for images pipeline


/ Published in: Python
Save to your folder(s)



Copy this code and paste it in your HTML
  1. # Small monkey patch for images pipeline to make it works with spider, which crawling Items of different nature (and some of this items doesn't have images)
  2.  
  3. from scrapy.contrib.pipeline.images import ImagesPipeline
  4.  
  5. old_item_completed = ImagesPipeline.item_completed
  6.  
  7. def new_item_completed(self, results, item, info):
  8. if 'image_urls' in item:
  9. return old_item_completed(self, results, item, info)
  10. else:
  11. return item
  12.  
  13.  
  14. if ImagesPipeline.item_completed != new_item_completed:
  15. ImagesPipeline.item_completed = new_item_completed
  16.  
  17. # Snippet imported from snippets.scrapy.org (which no longer works)
  18. # author: dchaplinsky
  19. # date : Nov 26, 2010
  20.  

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.