有人能告诉我为什么我的命令不起作用吗?
这是我的表格:
<form id="query" method="POST" action="https://weblogin.mycompany.com/"
enctype="application/x-www-form-urlencoded" autocomplete="off">
<table border="0" align="center">
<tr>
<td class="fieldname">Username:</td>
<td><input type="text" name="user" size="20" value="" class="inputfield" /> </td>
</tr>
<tr>
<td class="fieldname">Password:</td>
<td><input type="password" name="pass" class="inputfield" /></td>
</tr>
<tr>
<td class="fieldname"></td>
<td><input type="submit" value="Log in »" /></td>
</tr>
</table>
<div id='notifyuser'></div>
</form>
这是我的 wget 命令:
% wget --save-cookies /tmp/cookies.txt --post-data 'user=my_id&pass=my_passwd' \ https://weblogin.mycompany.com/
在我执行上面的 wget 命令后,cookie 文件是空的。
% cat /tmp/cookies.txt
# HTTP cookie file.
# Generated by Wget on 2013-07-02 16:23:39.
# Edit at your own risk.
和http响应:
% wget --keep-session-cookies --save-cookies /tmp/wget03_cookies.txt --post-data 'user=my_id&pass=my_passwd' **https://weblogin.mycompany.com/**
--2013-07-03 09:52:06-- https://weblogin.mycompany.com/
Resolving weblogin.mycompany.com... 1.1.1.1
Connecting to weblogin.mycompany.com|1.1.1.1|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 4477 (4.4K) [text/html]
Saving to: `index.html.10'
100%[===========================================================================>] 4,477 --.-K/s in 0s
2013-07-03 09:52:06 (36.8 MB/s) - `index.html.10' saved [4477/4477]
我做错了什么?
我可能会在这个线程中找到一个解决方案:wget with authentication
解决方案是这样的:
#!/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
我不明白的是——在生成隐藏数据时我应该用什么来代替“foobarhidden”?
我相信以下部分应该会给我答案。但我不知道具体该怎么做:
% grep value < loginpage.html | grep hidden
3:109:<input type=hidden name=pubcookie_g_req value="b25lPWFsb2hhLmFrYW1haS5jb20mdHdvPWFsb2hhJnRocmVlPTEmZm91cj1hNWEmZml2ZT1HRVQmc2l4PWFsb2hhLmFrYW1haS5jb20mc2V2ZW49THc9PSZlaWdodD0mYWthX2ZyYWc9Jmhvc3RuYW1lPWFsb2hhLmFrYW1haS5jb20mbmluZT0xJmZpbGU9JnJlZmVyZXI9KG51bGwpJnNlc3NfcmU9MCZwcmVfc2Vzc190b2s9NjMzMzQ0OTI3JmZsYWc9MA==">
4:110:<input type=hidden name=post_stuff value="">
5:111:<input type=hidden name=relay_url value="https://weblogin.mycompany.com/PubCookie.reply">
谢谢!!