web-dev-qa-db-ja.com

wgetがリンクを変換しない

大規模なオーバーホールの前に、かなり大きなサイト(20,000ページ以上)をミラーリングしようとしています。基本的に、必要なものを忘れた場合に備えて、新しいバックアップに切り替える前にバックアップが必要です(起動時に約1,000ページあります)。このサイトは、使用可能なデータを簡単に抽出できないCMSで実行されているため、wgetを使用してコピーを作成しようとしています。

私の問題は、コマンドに--convert-linksまたは-kが含まれているにもかかわらず、wgetが実際にリンクを変換していないように見えることです。フラグのいくつかの異なる組み合わせを試しましたが、必要な出力を取得できませんでした。最近失敗した試みは次のとおりです。

Nohup wget --mirror -k -l10 -PafscSnapshot --html-extension -R *calendar* -o wget.log http://www.example.org &

また、-kの代わりに--backup-convertedと--convert-linksを含めました(問題ではありません)。私は-Pと-lの有無にかかわらずそれを行いましたが、やはりそれらが重要であることはありません。

次のようなリンクがまだあるファイルになります。

http://www.example.org/ht/d/sp/i/17770
8
acrosman

これは古い投稿ですが、将来の検索者のためにここに答えを載せています。

--convert-links機能は、サイトのダウンロードが完了した後にのみ発生します。このような大規模なサイトでは、数ページが完了した後でプロセスを停止しようとしたため、プロセスはまだ開始されていなかったと思います。

参照 https://stackoverflow.com/questions/6348289/download-a-working-local-copy-of-a-webpage

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. 
11
mrisher

バックアップしようとしている6Gigサイトでも同じです。数日後、wgetはエラーメッセージなしで終了し、ステータス0を終了しますが、リンクは変換されません。同じオプションを使用して小さな検索を実行すると、問題なく機能します。これは、ダウンロードされたものの内部テーブルが、wgetが終了する前に洗浄または破損したかのようです。

-ncを使用してサイトを再フェッチしてみます(既にダウンロードされているため、何も再フェッチしないでください。リンクの変換で終了します-参照 wgetでHTMLリンクを相対的なものに変換します-kが指定されていない場合はダウンロード

1
commonpike

OSファイル名の制限のために wget -kはWindowsとLinuxでファイルを異なる方法で変換します に遭遇したかもしれませんか?

1
matt wilkie

マニュアルに従って-oもある場合、-kは無視されます。

「-k」との組み合わせは、単一のドキュメントをダウンロードする場合にのみ許可されることに注意してください。その場合、すべての相対URIが外部URIに変換されるだけです。 「-k」は、すべてが1つのファイルにダウンロードされている場合、複数のURIには意味がありません。 「-k」は、出力が通常のファイルである場合にのみ使用できます。

0
Chris