如何用Wget下载这个网页?

xRo*_*bot 6 script bash shell wget shell-script

我想下载网页http://forum.ubuntu-it.org/,但它需要用户名和密码。所以我使用了这个:

wget --save-cookies cookies.txt --post-data 'user=goyamy&passwrd=mypassword' http://forum.ubuntu-it.org/
Run Code Online (Sandbox Code Playgroud)

但它不起作用!为什么?

小智 6

这是一个示例脚本,它将从 Chrome (v19) 转储 cookie。

#!/bin/bash -e
#
# Quick and dirty script which dumps all Chrome cookies in 
# the specified SQLite database to stdout in Netscape format.

COOKIE_FILE='~/.config/google-chrome/Default/Cookies'

echo -e '.mode tabs \n select host_key, httponly, path, secure, ' \
  'expires_utc/10000000, name, value from cookies;' |
  sqlite3 $COOKIE_FILE |
  sed -e 's/\t0\t/\tFALSE\t/g ' -e 's/\t1\t/\tTRUE\t/g'
Run Code Online (Sandbox Code Playgroud)


Kib*_*bet 2

这可能是因为服务器使用会话 cookie 来跟踪身份验证。旁边添加选项--save-cookies以强制保存 cookie。所以你的命令看起来像这样:

wget --keep-session-cookies --save-cookies cookies.txt --post-data 'user=goyamy&passwrd=mypassword' http://forum.ubuntu-it.org/
Run Code Online (Sandbox Code Playgroud)

不过我还没有测试过。