Scrapy框架2-永久化存储

一、在items.py中设置永久化存储的字段

import scrapy


class Project1Item(scrapy.Item):
    # define the fields for your item here like:
    # name = scrapy.Field()
    title=scrapy.Field()
    #pass

二、持久化存储结果
没有导出也没有报错,当前问题原因未知。
2022/2/17
原因已确认,需要在settings.py文件中,开启管道如下:

ITEM_PIPELINES={
    'test1.pipelines.Test1Pipeline':300,
    }

备注:一个犯过的错误
如果在items.py文件中定义类如下:

class Test1Item(scrapy.Item):
    # define the fields for your item here like:
    # name = scrapy.Field()
    title = scrapy.Field()
    #pass

则在主文件number1.py中,类的应用是这样的,如下图:


image.png

item方框中的字符,要与items.py左边的字符相等

你可能感兴趣的:(Scrapy框架2-永久化存储)