def process_item(self, item, spider): insert_sql = """ insert into jobbole_article(title, url, fav_nums) VALUES (%s, %s, %s) """ self.cursor.execute(insert_sql, (item["title"], item["url"], item["fav_nums"])) self.conn.commit()
上面是插入数据表的代码,运行后会报错:_mysql_exceptions.IntegrityError: (1062, "Duplicate entry '' for key 'PRIMARY'")
然后检查数据表会发现只有一个数据插入了数据表