嗨,我的代码有问题我想检查管道 process_item 中的重复 ID,如果没有重复的 id,我将在表中插入项目
这是我的代码
def process_item(self, item, spider):
if isinstance(item, GPHM):
t = (item['hm_title'],)
rows_affected = self.curr.execute('SELECT
COUNT(hm_articode) from saleitems_hm WHERE hm_articode=?', t)
rows_affected = self.curr.rowcount
if rows_affected > 1:
global item_countHM
item_countHM += 1
self.store_db(item)
return item
def store_db(self, item):
self.curr.execute("""insert into saleitems_hm values (%s, %s, %s, %s, %s, %s)""", (
item['1'],
item['2'],
item['3'],
item['4'],
item['5'],
item['6']
))
self.conn.commit()
请问有什么想法吗?