web-dev-qa-db-ja.com

ウェブページの作業用ローカルコピーをダウンロードする

Webページのローカルコピーをダウンロードして、CSS、画像、JavaScriptなどをすべて入手したいのですが。

これまでの議論(例: herehere 、どちらも2年以上前)では、2つの提案が一般的に提案されています:wget -phttrack =。ただし、これらの提案は両方とも失敗します。これらのツールのいずれかを使用してタスクを実行することに協力していただければ幸いです。選択肢も素敵です。


オプション1:wget -p

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

例えば:

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

パスが正しくなるようにwget -pを修正する方法はありますか?


オプション2: httrack

httrackは、Webサイト全体をミラーリングするための優れたツールのようですが、それを使用して単一ページのローカルコピーを作成する方法はわかりません。このトピックについてはhttrackフォーラムで多くの議論があります(例えば here )が、誰もが防弾の解決策を持っているようには思われません。


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

有料ツールを提案している人もいますが、私はただそこに無料の解決策がないとは信じられません。

本当にありがとう!

193
brahn

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. 
243
serk