scrapy成功爬取数据,但插入不上mysql


 def process_item(self, item, spider):
        try:
            cursor = self.conn.cursor()
            if item['flag'] == 0:
                print("尝试第一页插入数据")
                sql = "replace into %s (id, replyNum, master, time, title, link, speechs) values (%s, %s, %s, %s, %s, %s, %s)"
                val = (item['school'], item['id'], item['replyNum'], item['master'], item['time'], item['title'], item['link'], item['speechs'])
                cursor.execute(sql, val)
                self.conn.commit()
                print("第一页插入成功")
            if item['flag'] == 1:
                print("尝试插入后续页回复")
                sql = "update  %s  set speechs = CONCAT(speechs, %s) where id = %s"
                val = (item['school'], item['replyNum'], item['id'])
                cursor.execute(sql, val)
                self.conn.commit()
                print("后续页插入成功")
        except:
            self.conn.rollback()
        finally:
            if cursor:
                cursor.close()
        return item

img


问题是,数据已经获取到了,可就是无法插入数据库,不清楚mysql语法有没有问题?我也是照着网上搜来的格式写的。

代码已经进入到if判断后了,,图片上有打印出来 ”尝试第一页插入数据“ ,可就没后面的消息了。
希望伙伴们可以看出问题来,咱明天就要交了。这是我毕设啊。还要继续写gui。

可以在except下打印下是否有异常产生

问题已解决。。把插入的表名 换了个方式写了。