ログインしたページとその依存関係をすべて取得するための簡単なコマンドがあります:
wget --post-data='user=user&password=password' --page-requisites https://…/login
サーバー ログには次の内容が表示されます (明らかな理由により省略されています)。
- POST /ログイン 302
- GET /アカウント 200
- POST /robots.txt 200 (GET のはずですが、成功しているので問題ありません)
- POST /favicon.ico 200 (同上)
- POST /[長いPageSpeed URL]500 (ページ上のすべての CSS、JavaScript、画像ファイルに対して)
これらのファイルの GET は正常に機能するため、URL は正しいのですが、PageSpeed はクライアントの POST を好まないようです。wget
最初のリクエスト以外のすべてに GET を使用するにはどうすればよいでしょうか?
GNU Wget 1.18 を使用します。
アップデート:バグ提出しました。
答え1
'man wget' より:
This example shows how to log in to a server using POST and then proceed to download the desired pages, presumably only accessible to authorized
users:
# Log in to the server. This can be done only once.
wget --save-cookies cookies.txt \
--post-data 'user=foo&password=bar' \
http://example.com/auth.php
# Now grab the page or pages we care about.
wget --load-cookies cookies.txt \
-p http://example.com/interesting/article.php
If the server is using session cookies to track user authentication, the above will not work because --save-cookies will not save them (and neither
will browsers) and the cookies.txt file will be empty. In that case use --keep-session-cookies along with --save-cookies to force saving of session
cookies.