1. ホーム
  2. download

[解決済み】ウェブページの作業用ローカルコピーのダウンロード【終了しました

2022-04-07 13:03:05

質問

ウェブページのローカルコピーをダウンロードして、css、画像、javascriptなどをすべて取得したいのですが。

これまでの議論(例. ここで こちら という2つの案が一般的である。 wget -p ヒットトラック . しかし、これらの提案は両方とも失敗しています。 これらのツールのいずれかを使用してタスクを達成するためのヘルプを非常に高く評価します;代替案も素敵です。



オプション1です。 wget -p

wget -p は、Webページの前提条件(css、images、js)をすべてダウンロードすることに成功しました。 しかし、ローカルコピーをウェブブラウザで読み込むと、前提条件へのパスがウェブ上のバージョンから変更されていないため、ページが前提条件を読み込むことができないのです。

例えば

  • ページのhtmlに <link rel="stylesheet href="/stylesheets/foo.css" /> の新しい相対パスを指すように修正する必要があります。 foo.css
  • cssファイルでは background-image: url(/images/bar.png) も同様に調整が必要です。

を修正する方法はありますか? wget -p のように、パスが正しく設定されていますか?



オプション 2: htrack

httrack は、ウェブサイト全体をミラーリングするための素晴らしいツールのようですが、1つのページのローカルコピーを作成するためにどのように使用するのかが不明です。 このトピックについては、httrackフォーラムで非常に多くの議論がなされています(例えば こちら しかし、誰も決定的な解決策を持っていないようです。



オプション3:別のツール?

有料のツールを提案される方もいらっしゃいますが、無料のソリューションがないとは信じられません。

解決するには?

wgetは、あなたが質問していることを行うことができます。以下を試してみてください。

wget -p -k http://www.example.com/

-p は、サイトを正しく表示するために必要なすべての要素(css、画像など)を取得します。 その -k は、すべてのリンク(CSS & 画像のリンクを含む)を変更し、オフラインでもオンラインと同じようにページを表示できるようにします。

Wgetのドキュメントより。

‘-k’
‘--convert-links’
After the download is complete, convert the links in the document to make them
suitable for local viewing. This affects not only the visible hyperlinks, but
any part of the document that links to external content, such as embedded images,
links to style sheets, hyperlinks to non-html content, etc.

Each link will be changed in one of the two ways:

    The links to files that have been downloaded by Wget will be changed to refer
    to the file they point to as a relative link.

    Example: if the downloaded file /foo/doc.html links to /bar/img.gif, also
    downloaded, then the link in doc.html will be modified to point to
    ‘../bar/img.gif’. This kind of transformation works reliably for arbitrary
    combinations of directories.

    The links to files that have not been downloaded by Wget will be changed to
    include host name and absolute path of the location they point to.

    Example: if the downloaded file /foo/doc.html links to /bar/img.gif (or to
    ../bar/img.gif), then the link in doc.html will be modified to point to
    http://hostname/bar/img.gif. 

Because of this, local browsing works reliably: if a linked file was downloaded,
the link will refer to its local name; if it was not downloaded, the link will
refer to its full Internet address rather than presenting a broken link. The fact
that the former links are converted to relative links ensures that you can move
the downloaded hierarchy to another directory.

Note that only at the end of the download can Wget know which links have been
downloaded. Because of that, the work done by ‘-k’ will be performed at the end
of all the downloads.