小编Dyl*_*l10的帖子

我收到错误“除了 MySQLdb.error,e”语法错误 - 尝试将我的 scrapy 蜘蛛写入 mysql 时语法无效,

这是我的 pipelines.py,我在第 18 行收到一个错误。

import sys;sys.path.append("/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages")
import MySQLdb
import hashlib
from scrapy.exceptions import DropItem
from scrapy.http import Request

class TestPipeline(object):

    def __init__(self):
        self.conn = MySQLdb.connect(user='test', passwd='password', db='c1024403', host='ephesus.cs.cf.ac.uk', charset='utf8', use_unicode=True)
        self.cursor = self.conn.cursor()

    def process_item(self, item, spider):
        try:
            self.cursor.execute("""INSERT INTO test (test1, test2) VALUES (%s, %s)""", (item['Country'], item['Qualification']))
            self.conn.commit()

        except MySQLdb.Error, e:
            print 'Error %d: %s' % (e.args[0], e.args[1])
            sys.exit(1)

        return item
Run Code Online (Sandbox Code Playgroud)

这是错误 -

File "project\pipelines.py", line 18
except MySQLdb.Error, e:
     ^
SyntaxError: invalid syntax
Run Code Online (Sandbox Code Playgroud)

我已经安装了 mysql-python 和 Visual c++ …

python mysql scrapy

1
推荐指数
1
解决办法
4756
查看次数

标签 统计

mysql ×1

python ×1

scrapy ×1