【发布时间】:2019-10-21 13:59:21
【问题描述】:
我正在尝试使用 scrapy 将抓取的数据存储到 sql 数据库,但出现以下错误:ProgrammingError: 1064 (42000): You have an error in your SQL syntax;检查与您的 MySQL 服务器版本相对应的手册,以在第 7 行的 ')' 附近使用正确的语法
请在下面找到我的 pipelines.py
from datetime import datetime
import mysql.connector
from mysql.connector import errorcode
class LecturesinparisPipeline(object):
...
class CleaningPipeline(object):
...
class DatabasePipeline(object):
def __init__(self):
self.create_connection()
self.create_table()
def create_connection(self):
self.conn = mysql.connector.connect(
host='localhost',
user='root',
passwd='sTUDIO987',
database='lecturesinparis_db'
)
self.curr = self.conn.cursor()
def create_table(self):
self.curr.execute("""DROP TABLE IF EXISTS mdl""")
self.curr.execute("""create table mdl(
title text,
location text,
startdatetime text,
lenght text,
description text,
)""")
def process_item(self, item, spider):
self.store_db(item)
return item
def store_db(self, item):
self.curr.execute("""insert into mdl values (%s,%s,%s,%s,%s)""", (
item['title'][0],
item['location'][0],
item['startdatetime'][0],
item['lenght'][0],
item['description'][0]
))
self.conn.commit()
【问题讨论】:
-
请显示完整的回溯,或告诉我们该消息属于哪些查询。
-
你给我们上课,但你没有展示你实际运行的代码
标签: python mysql sql database scrapy