只需将spider类解析到的src地址 yield item
pipelines.py写法
from itemadapter import ItemAdapter
from scrapy.pipelines.images import ImagesPipeline
import scrapy
class ImgPipeline(ImagesPipeline):
#根据图片的src进行图片数据请求
def get_media_requests(self,item,info):
yield scrapy.Request(item['src'])
#指定图片的存取名称
def file_path(self,request,response=None,info=None):
img_name = request.url.split('/')[-1]
return img_name
#返回给下一个管道类
def item_completed(self,results,item,info):
return item
setting.py中需加入设置
#图片存储路径
IMAGES_STORE = './ccc'