# noinspection PyUnresolvedReferences
import pymysql
# noinspection PyUnresolvedReferences
from douban.settings import mysql_db_name,mysql_password,mysql_table_name,mysql_host,mysql_username
class DoubanPipeline:
def __init__(self):
db = pymysql.connect(mysql_host, mysql_username, mysql_password, mysql_db_name)
cursor = db.cursor()
self.db = db
self.cursor = cursor
def process_item(self, item, spider):
insert_sql = '''INSERT INTO `douban`.`top250`
(`serial_number`, `movie_name`, `introduce`, `star`, `evaluate`, `describe`)
VALUES ({}, '{}', '{}', {}, '{}', '{}')'''.format(item['serial_number'],item['movie_name'],
item['introduce'],item['star'],
item['evaluate'],item['describe'])
self.cursor.execute(insert_sql)
self.db.commit()
# self.cursor.close()
# self.db.close()
return item