scrapy利用set()对数据进行去重

from scrapy.exceptions import DropItem  #导入异常处理模块

class Baidu03Pipeline(object): def __init__(self):   #建立构造方法 self.title = set()   #定义集合 def process_item(self, item, spider): title = item['title']   #取出要进行判断数据是否重复的字段 if title in self.title:   #如果存在集合中则直接删除该项, raise DropItem('{}已存在'.format(title)) self.title.add(title) #如果数据不重复,则加入集合 ...... #插库数据 写在这里即可。。。
return item

posted on 2018-11-06 14:22  泡8喝9耍10髦  阅读(768)  评论(0编辑  收藏  举报

导航