単一の特定のディレクトリにwget保存ページファイルを作成する

単一の特定のディレクトリにwget保存ページファイルを作成する

Firefox経由でWebページを保存すると、次のディレクトリ構造が表示されます。

.
├── Some Page/
└── Some Page.html

したがって、.htmlファイルと画像、JavaScript、CSSなどを含むフォルダがあります。

wget同じ結果(html +単一の大きなフォルダ)を取得するために(または他のコマンドラインツール)を使用できますか?

編集:複数のWebページをダウンロードし、時には各ページがダウンロードされた場所を確認するのが混乱しているため、これが必要です。

ベストアンサー1

問題を完全に理解できないかもしれませんが、簡単な解決策はその-rフラグを使用することです。だから:

wget -r www.site.com

最大5段階の深さのエントリは再帰的にクロールされ(-l NNが最大深さの場合は変更される可能性があります)、/www.site.com/に保存され、デフォルトでクロールされたURLが再生成されます。フォルダ構造はこのフォルダ内にあります。だからあなたは終わります:

.
├── www.site.com /
         └─────── pics
         |         └─── image1.jpg
         |         └─── image2.jpg
         └─────── index.html
         └─────── links.html

ただし、これを行うと、index.htmlファイルは現在のフォルダに保存されず、代わりにサイトフォルダに保存されます。

ディレクトリ構造で遊びたい場合は、パスを減らす方法についての情報があるマニュアルページがあります。

 Directory Options
       -nd
       --no-directories
           Do not create a hierarchy of directories when retrieving recursively.  With this option turned on, all files will get saved to the current directory, without clobbering (if a name shows up more than once, the filenames
           will get extensions .n).

       -x
       --force-directories
           The opposite of -nd---create a hierarchy of directories, even if one would not have been created otherwise.  E.g. wget -x http://fly.srk.fer.hr/robots.txt will save the downloaded file to fly.srk.fer.hr/robots.txt.

       -nH
       --no-host-directories
           Disable generation of host-prefixed directories.  By default, invoking Wget with -r http://fly.srk.fer.hr/ will create a structure of directories beginning with fly.srk.fer.hr/.  This option disables such behavior.

       --cut-dirs=number
           Ignore number directory components.  This is useful for getting a fine-grained control over the directory where recursive retrieval will be saved.

           Take, for example, the directory at ftp://ftp.xemacs.org/pub/xemacs/.  If you retrieve it with -r, it will be saved locally under ftp.xemacs.org/pub/xemacs/.  While the -nH option can remove the ftp.xemacs.org/ part,
           you are still stuck with pub/xemacs.  This is where --cut-dirs comes in handy; it makes Wget not "see" number remote directory components.  Here are several examples of how --cut-dirs option works.

                   No options        -> ftp.xemacs.org/pub/xemacs/
                   -nH               -> pub/xemacs/
                   -nH --cut-dirs=1  -> xemacs/
                   -nH --cut-dirs=2  -> .

                   --cut-dirs=1      -> ftp.xemacs.org/xemacs/
                   ...

           If you just want to get rid of the directory structure, this option is similar to a combination of -nd and -P.  However, unlike -nd, --cut-dirs does not lose with subdirectories---for instance, with -nH --cut-dirs=1, a
           beta/ subdirectory will be placed to xemacs/beta, as one would expect.

おすすめ記事