Now I want to save the picture with the original name
It seems that there are no direct parameters to pass, so you need to implement the Images Pipeline yourself
scrapy.contrib.pipeline.images.ImagesPipeline class get_media_requests(item, info) will download the image and feed the result to the item_completed() method. The result is a tuple, (success, image_info_or_failure), where success is a bool indicating whether the download is successful, image_info_or_failure includes url, path and checksum three items. Among them, path is the path (including file name) relative to IMAGES_STORE.
Look at the source code of ImagePipeline and find that you can rewrite the file_path function to modify the image name, for example:
The source code of ImagePipeline is as follows:
It seems that there are no direct parameters to pass, so you need to implement the Images Pipeline yourself
scrapy.contrib.pipeline.images.ImagesPipeline
classget_media_requests(item, info)
will download the image and feed the result to theitem_completed()
method. The result is a tuple,(success, image_info_or_failure)
, wheresuccess
is a bool indicating whether the download is successful,image_info_or_failure
includesurl
,path
andchecksum
three items. Among them,path
is the path (including file name) relative toIMAGES_STORE
.The above is an example from the official website.
So what you need to do is rewrite the
item_completed(results, items, info)
method and replaceitem['image_paths']
with the original file name.Modifying file_path is too intrusive to the original code. If it is just to modify the file path, you can rename the file in item_completed.