# 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


# useful for handling different item types with a single interface
from itemadapter import ItemAdapter
import os
import csv

class MyspiderPipeline:

    def __init__(self):
        # csv 文件
        store_file = os.path.dirname(__file__)+"/spiders/school1.csv"
        self.file = open(store_file,"a+",newline='',encoding="utf-8")
        self.writer = csv.writer(self.file)

    def process_item(self, item, spider):
        try:
     
            self.writer.writerow((
                item["title"],
                item["userName"],
                item["createTime"]
            ))

        except Exception as e:
            print(e.args)


    def close_spider(self,spider):
        self.file.close()

