37

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

パスを自動的に作成して保存するようにするにはどうすればよいですか?

4

6 に答える 6

70

試すcurl

curl http://www.site.org/image.jpg --create-dirs -o /path/to/save/images.jpg
于 2012-06-29T08:19:20.173 に答える
7
mkdir -p /path/i/want && wget -O /path/i/want/image.jpg http://www.com/image.jpg
于 2012-06-29T08:14:54.827 に答える
3

wgetを使用してファイルを新しいディレクトリにダウンロードするには、 :--directory-prefix なし で使用します。-O

wget --directory-prefix=/new/directory/ http://www.example.com/old_image.jpg

-O new_fileと組み合わせて使用​​すると--directory-prefix新しいディレクトリ構造は作成されず、新しいファイルが現在のディレクトリに保存されます。指定すると、「そのようなファイルまたはディレクトリはありません」というエラーで失敗することもあります。-O /new/directory/new_file

于 2020-05-20T21:10:34.710 に答える
2

このコマンドでフォルダが存在しない場合は、フォルダを作成できました。
wget -N http://www.example.com/old_image.jpg -P /path/to/image

于 2020-06-15T00:52:44.117 に答える
1

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
于 2012-06-29T08:29:38.173 に答える
0

たくさん検索した後、私はついに存在しないパスをダウンロードするために使用する方法を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)

Happy wget-ing!

于 2018-08-15T00:07:59.703 に答える