在使用scrapy保存文件时我们有可能会遇到保存多个数据到不同的文件中,这里我们可以设置多个items,来进行保存下面时代码`
from shares.items import New_spider,SharesItem
class SharesPipeline(object):
def process_item(self, item, spider):
if isinstance(item,SharesItem):
#isinstance(item,SharesItem):用来判断当前的items名字,通过这里实现保存到不同的地方
with open('one.txt','a+')as f:
f.write(str(item))
if isinstance(item,New_spider):
with open('two.txt','a+')as f:
f.write(str(item))
return item