我如何知道哪个图像已使用自定义图像管道下载?
How can I know which image has been downloaded with a custom image pipeline?
我创建了一个包含两张图片的 scrapy 项目。这些图像需要在我的项目管道中进行 post 处理。但是,这两张图片有不同的 post 处理需求。
我的图像管道目前是这样的:
import scrapy
from scrapy.contrib.pipeline.images import ImagesPipeline
from scrapy.exceptions import DropItem
class CustomImagePipeline(ImagesPipeline):
def get_media_requests(self, item, info):
yield scrapy.Request(item['image_1'][0])
yield scrapy.Request(item['image_2'][0])
def item_completed(self, results, item, info):
# if image_1 is completed do one thing.
# if image_2 is completed to another thing.
return item
如何在item_completed
回调方法中知道哪张图片已经完成?
我能以某种方式在 results
字典中追加一个字段吗?
根据the docs,可以判断哪个图是哪个--
def item_completed(self, results, item, info):
for result in [x for ok, x in results if ok]:
# Invoke relevant post-processing based on result['url']
return item
我创建了一个包含两张图片的 scrapy 项目。这些图像需要在我的项目管道中进行 post 处理。但是,这两张图片有不同的 post 处理需求。
我的图像管道目前是这样的:
import scrapy
from scrapy.contrib.pipeline.images import ImagesPipeline
from scrapy.exceptions import DropItem
class CustomImagePipeline(ImagesPipeline):
def get_media_requests(self, item, info):
yield scrapy.Request(item['image_1'][0])
yield scrapy.Request(item['image_2'][0])
def item_completed(self, results, item, info):
# if image_1 is completed do one thing.
# if image_2 is completed to another thing.
return item
如何在item_completed
回调方法中知道哪张图片已经完成?
我能以某种方式在 results
字典中追加一个字段吗?
根据the docs,可以判断哪个图是哪个--
def item_completed(self, results, item, info):
for result in [x for ok, x in results if ok]:
# Invoke relevant post-processing based on result['url']
return item