1 回答
TA贡献1765条经验 获得超5个赞
您需要将管道重构为如下所示:
class DatabasePipeline(object):
def open_spider(self, spider):
#Create database connection
...
#create items list
self.items = []
def process_item(self,item,spider):
self.items.append(item)
if len(self.items)==100:
#constuct SQL query to insert multiple records
...
#execute query and clean self.items
self.items = []
return item
def close_spider(self,spider):
#insert remaining records
if self.items:
#constuct SQL query to insert multiple records
...
#execute query
#close database connection
添加回答
举报