我无法wget
,因为还没有要保存的路径。我的意思是,wget
不适用于不存在的保存路径。例如:
wget -O /path/to/image/new_image.jpg http://www.example.com/old_image.jpg
如果/path/to/image/
以前不存在,则始终返回:
No such file or directory
如何使其自动创建路径并保存?
尝试curl
curl http://www.site.org/image.jpg --create-dirs -o /path/to/save/images.jpg
mkdir -p /path/i/want && wget -O /path/i/want/image.jpg http://www.com/image.jpg
要使用 wget 将文件下载到新目录中,请使用不带 -O
的--directory-prefix
:
wget --directory-prefix=/new/directory/ http://www.example.com/old_image.jpg
将-O new_file
与 --directory-prefix
结合使用,将不会创建新的目录结构,并将新文件保存在当前目录中。如果您指定-O /new/directory/new_file
,它甚至可能因"没有此类文件或目录"错误而失败
它不存在,我可以使用以下命令创建文件夹:
wget -N http://www.example.com/old_image.jpg -P /path/to/image
wget 只获取一个文件,而不是为您创建目录结构(mkdir -p/path/to/image/),您必须自己执行此操作:
mkdir -p /path/to/image/ && wget -O /path/to/image/new_image.jpg http://www.example.com/old_image.jpg
你可以告诉 wget 使用参数创建目录(这样你就不必使用 mkdir --force-directories
总而言之,这将是
wget --force-directories -O /path/to/image/new_image.jpg http://www.example.com/old_image.jpg
经过大量搜索,我终于找到了一种使用wget
下载不存在路径的方法。
wget -q --show-progress -c -nc -r -nH -i "$1"
=====
Clarification
-q
--quiet --show-progress
Kill annoying output but keep the progress-bar
-c
--continue
Resume download if the connection lost
-nc
--no-clobber
Overwriting file if exists
-r
--recursive
Download in recursive mode (What topic creator asked for!)
-nH
--no-host-directories
Tell wget do not use the domain as a directory (for e.g: https://example.com/what/you/need
- without this option, it will download to "example.com/what/you/need")
-i
--input-file
File with URLs need to be download (in case you want to download a lot of URLs,
otherwise just remove this option)
祝你快乐!