botao555
2020-09-23 17:39
# 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
为什么要close呢?
Python最火爬虫框架Scrapy入门与实践
67418 学习 · 223 问题
相似问题