scrapy爬数据存mysql报错


最近学习python,遇到一个奇葩问题,跪求高手解答

这是数据直接存的json文件
clipboard.png
存mysql就会报如下错误
clipboard.png
pipeline代码如下:


 from twisted.enterprise import adbapi             
import MySQLdb
import MySQLdb.cursors

class TutorialPipeline(object):
    def __init__(self):                         
        self.dbpool = adbapi.ConnectionPool('MySQLdb',
                db = 'test',
                user = 'root',
                passwd = '123456',
                cursorclass = MySQLdb.cursors.DictCursor,
                charset = 'utf8',
                use_unicode = False
        )

    # pipeline dafault function              
    def process_item(self, item, spider):
        query = self.dbpool.runInteraction(self._conditional_insert, item)
        return item

    # insert the data to databases                
    def _conditional_insert(self, tx, item):
        sql = "insert into test values (%s,%s)"
        tx.execute(sql, (item['link'],item['title']))

scrapy

tesaaa 9 years, 4 months ago

留意里边的引号与转义符号:\,看看SQL语句拼接时有没有问题,一步步调试下。目测是你SQL语句有问题,引号与\
结合导致的问题。

ddsa answered 9 years, 4 months ago

Your Answer