在item.py中,我定义了图像文件。在settings.py中,还定义了IMAGES_URLS_FIELD,IMAGES_STORE。
在spider.py中,图像是在解析函数中获得的。当有有效的图像网址时,它工作正常。问题是图像字段可能是无。它将无法在pipelines.py中请求无错误。
我尝试为图片字段设置默认网址值,但不起作用。
这是我的piplelines:
def get_media_requests(self, item, info):
yield Request(item["image"])
def item_completed(self, results, item, info):
image_paths = [x['path'] for ok, x in results if ok]
if not image_paths:
raise DropItem("Item contains no images")
item['image'] = image_paths
return item
如果图像字段为空时如何设置默认值?