pipelines.py文件中新建MySQLPipeline类:
# 导入库
from scrapy.utils.project import get_project_settings
import pymysql
# 写入数据库
class MySQLPipeline(object):
def connect_db(self):
# 从settings.py文件中导入数据库连接需要的相关信息
settings = get_project_settings()
self.host = settings['DB_HOST']
self.port = settings['DB_PORT']
self.user = se