LoginSignup
18
19

More than 5 years have passed since last update.

wgetでページとそれに付随するCSS・JSなどを保存する

Posted at

wgetでひとつのページとそのページが使っている画像・CSS・JSなどのアセットも同時に保存する方法です。

wget --page-requisites \
     --convert-links \
     --quiet --show-progress \
     --no-host-directories  http://example.com/

パラメータの説明

  • --page-requisites: ページが使っている画像・CSS・JSをダウンロードします。
  • --convert-links: CSS・JSへの参照がURLになっている部分を相対パスに変換します。
  • --quiet --show-progress: 1ダウンロード1行で表示する設定です。
  • --no-host-directories: ホスト名でディレクトリを作らない設定です。

ダウンロードしたファイルの確認方法

ダウンロードしたファイルを確認するには、index.htmlを開く方法もありますが、google fontsなどCDNに依存しているHTMLだとエラーになるので、ダウンロードしたindex.htmlがある場所でPythonのSimpleHTTPServerを立てて、http://localhost:4000などにアクセスし確認するとよいです。

python -m SimpleHTTPServer 4000
18
19
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
18
19