爬虫写入数据库时报错:
AttributeError: module 'MySQLdb' has no attribute 'cursors'

解决方法:
引入
import MySQLdb.cursors# 引入这个依赖
如下所示
import codecs
import json
from scrapy.pipelines.images import ImagesPipeline
from scrapy.exporters import JsonItemExporter
from twisted.enterprise import adbapi
import MySQLdb
import MySQLdb.cursors# 引入这个依赖

本文解决了一种常见的爬虫编程问题,即在尝试将爬取的数据写入MySQL数据库时遇到的AttributeError:模块'MySQLdb'没有属性'cursors'。通过正确导入MySQLdb.cursors依赖,该问题得以解决,确保了数据能够顺利存入数据库。
2万+

被折叠的 条评论
为什么被折叠?



