【问题标题】:how to use scrapy download images and then upload to s3 server如何使用scrapy下载图片然后上传到s3服务器
【发布时间】: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

【问题讨论】:

    标签: python mongodb scrapy


    【解决方案1】:

    你可以简单地使用self,但我真的建议你使用our pipeline

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-06-01
      • 2016-11-29
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多