wget与身份validation
如何下载需要用户名和密码的网页?
例如,我想在input用户名和密码后下载此页面:
http://forum.ubuntu-it.org/index.php
试试这里介绍的解决scheme:
- 
http://www.unix.com/shell-programming-scripting/131020-using-wget-curl-http-post-authentication.html # Log in to the server. This can be done only once. wget --save-cookies cookies.txt \ --post-data 'user=foo&password=bar' \ http://server.com/auth.php # Now grab the page or pages we care about. wget --load-cookies cookies.txt \ -p http://server.com/interesting/article.php
注意其他人可能会遇到这种情况:
-  以上模拟用户手动login到一个具有两个input字段的表单:一个名为user和一个名为password的表单
-  表单的action属性设置为http://server.com/auth.php
-  表单不使用JavaScript
-  它使用JavaScript的一个很好的提示是form元素上的onsubmit属性
- 请注意,这是设置属性的唯一方法 – 在页面的任何位置使用JavaScript,或者任何静态或dynamic加载的脚本文件都可以更改表单元素
 
-  它使用JavaScript的一个很好的提示是form元素上的
- 看到这个最好的方法是加载页面,并用Firebug for Firefox进行实时检查
 因此,如果属性名称和表单动作url不同,则需要适当地将参数更改为第一个wget命令。 
 如果使用JavaScript,则有可能根本无法工作 – 例如在OP的网站示例中,它使用客户端JavaScript散列,因此使用wget的外部调用不会在窗体上设置必要的字段(在Ubuntu站点的情况下, hash_passwrd字段)。 
使用选项:
 --password=PASS --user=USERNAME 
 即: wget http://www.example.com --user=joe --password=schmoe 
 如果--auth-no-challenge其他问题,还可以添加--auth-no-challenge参数: 
 即: wget http://www.example.com --user=joe --password=schmoe --auth-no-challenge 
以下wget命令应该允许您访问需要用户名和密码的网站:
 wget http://username:password@example.org/url/ wget --http-user=user --http-password=password http://example.org/url/ 
也许这会有所帮助。 我试图login的网站有一些隐藏的领域,我需要得到之前,我可以成功login。 因此,第一个wget获取login页面来查找额外的字段,第二个wgetlogin到网站并保存cookie,第三个则使用这些cookie来获取您之后的页面。
 #!/bin/sh # get the login page to get the hidden field data wget -a log.txt -O loginpage.html http://foobar/default.aspx hiddendata=`grep value < loginpage.html | grep foobarhidden | tr '=' ' ' | awk '{print $9}' | sed s/\"//g` rm loginpage.html # login into the page and save the cookies postData=user=fakeuser'&'pw=password'&'foobarhidden=${hiddendata} wget -a log.txt -O /dev/null --post-data ${postData} --keep-session-cookies --save-cookies cookies.txt http://foobar/default.aspx # get the page your after wget -a log.txt -O results.html --load-cookies cookies.txt http://foobar/lister.aspx?id=42 rm cookies.txt 
在这个post上有一些有用的信息: 超级用户 – >使用wget从需要设置cookie的站点下载pdf文件
 使用选项--user=X --password=Y指定X的用户名和Y的密码。