pipeline文件: import MySQLdb class Task1Pipeline(object): def process_item(self, item, spider): task1_db = spider.settings.get('task1_db') con = MySQLdb.connect(**task1_db) cur = con.cursor() sql = ("insert into person_in (client_name,quaification,get_method,certificate_n,office,class_hour,penalty_in)" "values(%s,%s,%s,%s,%s,%s,%s)") lis = (item['client_name'],item['quaification'],item['get_method'],item['certificate_n'], item['office'],item['class_hour'],item['penalty_in']) cur.execute(sql,lis) con.commit() cur.close() con.close() return item
settings.py中文件
BOT_NAME = 'task1' SPIDER_MODULES = ['task1.spiders'] NEWSPIDER_MODULE = 'task1.spiders' task1_db = {'db':'task1_db','user':'root','passwd':'fy', 'host':'localhost','use_unicode':True,'charset':'utf8'} ITEM_PIPELINES = { 'task1.pipelines.Task1Pipeline':300, }
报错:
TypeError: Connect() argument after ** must be a mapping, not NoneType
我就不懂了,按照别人源文件修改的,mysql已经建立task1_db这个数据库,为什么会报错怎么改??
defsetmodule(self,module,priority='project'):"""Storesettingsfromamodulewithagivenpriority.Thisisahelperfunctionthatcalls:meth:`~scrapy.settings.BaseSettings.set`foreverygloballydeclareduppercasevariableof``module``withtheprovided``priority``.:parammodule:themoduleorthepathofthemodule:typemodule:moduleobjectorstring:parampriority:thepriorityofthesettings.Shouldbeakeyof:attr:`~scrapy.settings.SETTINGS_PRIORITIES`oraninteger:typepriority:stringorint"""self._assert_mutability()ifisinstance(module,six.string_types):module=import_module(module)forkeyindir(module):ifkey.isupper():self.set(key,getattr(module,key),priority)
所以,task1_db必须全大写
虽然看不懂前面一大段,不过最后结论超给力~我马上试试看版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。