# Define your item pipelines here
#
# Don't forget to add your pipeline to the ITEM_PIPELINES setting
# See: https://docs.scrapy.org/en/latest/topics/item-pipeline.html
# useful for handling different item types with a single interface
from itemadapter import ItemAdapter
import pymysql
class QunanPipeline:
def process_item(self, item, spider):
return item
class QunanmysqlPipeline:
def process_item(self, item, spider):
insert_sql = "insert into lyone value(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)"
self.cur.execute(insert_sql, [item['tit'], item['user_name'], item['date'], item['days'],
item['photo_nums'], item['fee'], item['people'], item['icon_view'],
item['icon_love'], item['icon_comment'], item['places'], item['places1']])
self.db.commit()
return item
def open_spider(self,spider):
self.db = pymysql.connect(host="127.0.0.1", user="root", password="123456",
database="qunar", port=3306, charset='utf8')
self.cur = self.db.cursor()
def close_spider(self,spider):
self.db.close()
self.cur.close()
```python
pymysql.err.ProgrammingError: (1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '),('3.4万'),('
129'),('14'),('途经:'),('行程:','城墙','博物院','大' at line 1")
sql 关键字错误
insert into lyone value
改成
insert into lyone values