Scrapy item pipelines parallel or sequential execution of process_item
我正在开发一只刮y的蜘蛛,它成功地产生了一些物品。这些项目应使用pymysql插入数据库中。因为数据是关系数据,所以对于每一项我都必须执行一些插入语句。
我想在每次完整插入后调用
我目前在想,scrapy是否会为多个项目并行调用
1 2 3 | def process_item(self, item, spider): # execute insert statements connection.commit() |
如果通过刮擦同时执行了多次对
项目管道的文档指出:
After an item has been scraped by a spider, it is sent to the Item Pipeline which processes it through several components that are executed sequentially.
但是我不确定这是否意味着
我认为
1 2 3 4 5 6 7 8 9 10 11 | class DuplicatesPipeline(object): def __init__(self): self.ids_seen = set() def process_item(self, item, spider): if item['id'] in self.ids_seen: raise DropItem("Duplicate item found: %s" % item) else: self.ids_seen.add(item['id']) return item |
在此代码中,没有将id添加到所涉及的
CONCURRENT_ITEMS设置的文档指定以并行方式处理项目(至少在单个响应中)。 我认为将其设置为
我对Scrapy的这一部分不是专家,但是我相信这是发生的地方。