More reliable solution; I canโt remember where I found it, but scrapy dev suggested it somewhere. Using this method, you can use some kind of conveyor for all spiders without using a shell. It also makes it so that you donโt need to duplicate the logic of checking whether to use a pipeline.
Packing:
def check_spider_pipeline(process_item_method): """ This wrapper makes it so pipelines can be turned on and off at a spider level. """ @functools.wraps(process_item_method) def wrapper(self, item, spider): if self.__class__ in spider.pipeline: return process_item_method(self, item, spider) else: return item return wrapper
Using:
@check_spider_pipeline def process_item(self, item, spider): ........ ........ return item
Spider use:
pipeline = {some.pipeline, some.other.pipeline .....}
source share