【发布时间】:2014-09-10 02:30:12
【问题描述】:
我想在蜘蛛关闭时将图像上传到 s3,
我现在的方法是在 mongodb 中发送所有图像:upload_s3(ShA.objects.all())
但是这次我想编辑它以发送scrapy下载的图像。
我需要将变量sh.images从def process_item()发送到def close_spider(),让mongo这次过滤scrapy爬取的项目
我如何编辑才能达到它?
这是我的管道:
from mongo.models import ShA
from uploads3 import upload_s3
class ShPipeline(object):
def process_item(self, item, spider):
if isinstance(item, ShaItem):
sh = item.save(commit=False)
sh_exist = ShA.objects.filter(link=sh.link)
if sh_exist:
sh.id = sh_exist[0].id
sh.save()
#sh.images
return item
def close_spider(self, spider,item):
if spider.name == "email":
upload_s3(ShA.objects.all())
#upload_s3(ShA.objects.get(images=sh.images)) no use,need to get sh.images from def process_item
【问题讨论】: