scrapy pipelines.py文件<class'RuntimeError'>:生成器引发的停止迭代pylint(astroiderror)

2024-05-15 00:06:53 发布

您现在位置:Python中文网/ 问答频道 /正文

# -*- 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错误)”,我似乎找不到任何解决方案。我非常感谢您的帮助


Tags: totextselfyourgetpipelineobjectdef

热门问题