Я пытаюсь сохранить мои очищенные данные с помощью scrapy в базу данных SQL, но мой код ничего не отправляет, хотя при запуске не упоминается об ошибке.
Я использую свой SQL-коннектор, так как мне не удается установить MySQL-python. Моя база данных SQL работает нормально, и когда я запускаю код, трафик увеличивается в КБ / с. Пожалуйста, найдите ниже мой pipelines.py код.
import mysql.connector
from mysql.connector import errorcode
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 = '********',
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()