2.piplines

# -*- coding: utf-8 -*-

# Define your item pipelines here
#
# Don't forget to add your pipeline to the ITEM_PIPELINES setting
# See: https://doc.scrapy.org/en/latest/topics/item-pipeline.html


class MyfirstscrapyPipeline(object):
    # 这个类是一个管道类,继承自基本类,我们在settings文件中如果把这个类设置成了管道类,这个类就具备管道的所有的功能

    def open_spider(self,spider):
        # 当爬虫开启的时候会回调这个方法
        print("爬虫被开启了!")
        pass

    def process_item(self, item, spider):
        # 爬虫在对parse方法中的可迭代对象进行迭代的时候,每迭代一次就会调用一次这个方法
        print("hello,我是管道,我被调了!")
        return item

    def close_spider(self,spider):
        print("爬虫被关闭了!")




©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容