end0tknr's kipple - web写経開発

太宰府天満宮の狛犬って、妙にカワイイ

wgetの--convert-lineによるダウンロード時のurl変換

wgetでコンテンツを取得する際、--convert-lineを付けると、コンテンツに含まれるaタグのリンク先をlocalfile?に変更できます。

$ wget \
  --html-extension \
  --mirror \
  --convert-links \
  --no-host-directories \
  --no-parent
  http://localhost

例えば、上記のようにwgetを実行すると、全対象コンテンツをダウンロード後、変換処理が実行されます。

    [ <=>                                  ] 10,544      --.-K/s   in 0s
2009-04-15 14:10:02 (89.8 MB/s) - `wiki3_5_10/wiki.cgi.html' saved [10544]

##### ここからが、ダウンロード後の変換処理
FINISHED --2009-04-15 14:10:02--
Downloaded: 3 files, 11K in 0s (21.3 MB/s)
Converting index.html... 2-0
Converting wiki3_5_10/wiki.cgi.html... 1-67
Converted 2 files in 0.02 seconds.
変換前) <a href="http://localhost/wiki3_5_10/wiki.cgi">wiki</a>
変換後) <a href="wiki3_5_10/wiki.cgi.html">wiki</a>

今回の例では、--html-extension で強制的にhtmlの拡張子を付加しています。