插入语句有两条,循环插入这两条
只是简单写了下插入语句,没有捕捉到异常
def process_item(self, item, spider):
#print(item)
try:
with self.connection.cursor() as cursor:
#Create a new record
sql1 = "INSERT INTO staff (XNXQ, \
department, \
teacher, \
gender, \
title, \
note1, \
note2) VALUES (%s, %s, %s, %s, %s, %s, %s)"
cursor.execute(sql1, (item['first']['XNXQ'],
item['first']['department'],
item['first']['teacher'],
item['first']['gender'],
item['first']['title'],
item['first']['note1'],
item['first']['note2']))
self.connection.commit()
#Create a new record
cursor.execute("select max(id) from staff")
teacherId = cursor.fetcho