import pymysql as pq
class Pipeline(object): def init(self): self.conn = pq.connect(host='127.0.0.1', user='root',port='3306', passwd='123456', db='root', charset='utf8') self.cur = self.conn.cursor() # def init(self): # host = '127.0.0.1' # port = 27017 # client = pymongo.MongoClient(host=host,port=port) # collection = client.local.letsgojpt # self.post = collection
def process_item(self, item, spider):
for i in range(0,len(item["title_all"])):
# sql = "insert into letsgojp(title_all, center_all) VALUES (%s, %s)"
self.cur.execute("insert into letsgojp(title_all,center_all) values(%s,%s)",(item['title_all'][i],item['center_all'][i]))
self.conn.commit()
# self.post.insert(data)
return item
def close_spider(self, spider):
self.cur.close()
self.conn.close()
主要是这行报错
self.cur.execute("insert into letsgojp(title_all,center_all) values(%s,%s)",(item['title_all'][i],item['center_all'][i]))
用 mongo 的时候是正常存数据的,但是用 mysql 就报错,网上找一些,不太会用,请教各位大神了
这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。
V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。
V2EX is a community of developers, designers and creative people.