Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/362.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python scrapy,每个项目管道包装在spider文件中_Python_Import_Scrapy_Decorator - Fatal编程技术网

Python scrapy,每个项目管道包装在spider文件中

Python scrapy,每个项目管道包装在spider文件中,python,import,scrapy,decorator,Python,Import,Scrapy,Decorator,我将scrapy用于一个项目,该项目的项目管道是专门为需要插入数据库的项目字段设计的。我正在使用python decorator方法来实现这一点。由于某些原因,我无法理解这个问题,我得到了一个特殊的名称错误,我不知道它们是从哪里来的。 注:人们已经证实,这种方法工作得非常好 这是我在spider.py文件中的代码: from scrapy.spider import Spider from scrapy.http import Request,FormRequest from exampleSc

我将scrapy用于一个项目,该项目的项目管道是专门为需要插入数据库的项目字段设计的。我正在使用python decorator方法来实现这一点。由于某些原因,我无法理解这个问题,我得到了一个特殊的名称错误,我不知道它们是从哪里来的。 注:人们已经证实,这种方法工作得非常好

这是我在spider.py文件中的代码:

from scrapy.spider import Spider
from scrapy.http import Request,FormRequest
from exampleScraper.items import exampleItem
import urllib, time, MySQLdb, sys

today = time.strftime("%x %X")

class idoxpaSpider(Spider):
  pipeline = set(['insert'])

  name = 'idoxpaSpider'

  start_urls = ["http://www.example.com"]
  ###
  def parse(self, response):
    # some scrapy work 
    return item

###
class insert(object):
  def __init__(self):
    self.conn = MySQLdb.connect(<some parameters>)
    self.cursor = self.conn.cursor()

  @check_spider_pipeline
  def process_item(self, item, spider):
    return item
这是我得到的一个严重错误:

File "/home/mn/workbench/boroughScrper/boroughScrper/spiders/westminsterSpider.py", line 40, in insert
    @check_spider_pipeline
NameError: name 'check_spider_pipeline' is not defined

知道哪里出了问题吗?

由于找不到它,所以
检查蜘蛛\u管道
是“未定义”的。它不在您的
spider.py
脚本可见的范围内,而是在
BoroughscrperPipeline.process\u项的局部变量中定义的。您需要使其在您的范围内可见。请勾选此答案,例如:

File "/home/mn/workbench/boroughScrper/boroughScrper/spiders/westminsterSpider.py", line 40, in insert
    @check_spider_pipeline
NameError: name 'check_spider_pipeline' is not defined