这是我的 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++ …