# -*- coding: utf-8 -*-
# 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
import sqlite3
class RecipesPipeline(object):
def open_spider(self,spider):
self.connection = sqlite3.connect("recipes.db")
#To use sql queries we need to create a cursor object .
self.c = self.connection.cursor()
self.c.execute('''
CREATE TABLE FoodRecipes(
Name TEXT,
Ingredients TEXT,
Directions TEXT
)
''')
self.connection.commit()
def close_spider(self,spider):
self.connection.close()
def process_item(self, item, spider):
self.c.execute('''
INSERT INTO FoodRecipes(Name,Ingredients,Directions) VALUES(?,?,?)
''',(
item.get('recipe_name'),
item.get('recipe_ingredients'),
item.get('recipe_directions')
))
self.connection.commit()
return item
您好,这是我的pipelines.py文件,在这里我试图将我的刮取数据存储到sqlite数据库中,但我一直收到这个错误:“generator引发的StopIteration pylint(astroid错误)”,我似乎找不到任何解决方案。我非常感谢您的帮助
目前没有回答
相关问题 更多 >
编程相关推荐