我在这里发表问题之前做了2周的研究。我可以访问它,但它需要登录才能访问内容。
我想知道如何通过wget登录并通过wget访问它的内容?这是基本的html登录。
以下是网站的HTML代码。
<div id="loginh">
<div id="form">
<form name="frmLogin" action="/en/login.shtml" method="post">
<input type="hidden" name="login_attempt" value="yes">
<input type="hidden" name="redirect" value="/en/index.shtml">
<input type="text" name="login_username" class="txtBox1" title="Enter your user name" id="username" value="User name" onfocus="clickLoginField(this);" onkeypress="javascript:if ((event.which && event.which == 13)||(event.keyCode && event.keyCode == 13)) {document.frmLogin.login_password.focus(); return false;}">
<input type="password" name="login_password" class="txtBox2" title="Enter your password" id="pass" value="" onkeypress="javascript:if ((event.which && event.which == 13)||(event.keyCode && event.keyCode == 13)) { document.frmLogin.submit(); return false;}">
<input type="text" id="login_password_" name="login_password_" class="loginattemptstyle" value="">
<a class="login" href="javascript:void(0);" onclick="document.frmLogin.submit();">Login</a><noscript><input type="submit" value="Login"/></noscript>
<div class="clear"></div>
<table width="100%" cellpadding="5">
<tbody><tr>
<td><a href="/en/forgottenpassword.shtml" title="Have you forgotten your password?">Forgotten password?</a></td>
<td><table width="100%">
<tbody><tr>
<td><input type="checkbox" name="login_remember" style="margin-left: 0; margin-right: 5px;"></td>
<td>Stay signed in</td>
</tr>
</tbody></table></td>
</tr>
</tbody></table>
</form>
</div>
<script language="JavaScript" type="text/JavaScript">
<!--
$("#login_password_").val('1tCRztiXpM5jpmefqdWYn4O/ipyn5KWUneZoag==');
//-->
</script>
</div>
我尝试了什么
wget -q -O- save.txt --load-cookies cookies.txt http://mysite.com/en/article1.shtml | findstr /i "'streamer'" > save3.txt
答案 0 :(得分:2)
您需要执行POST而不是GET REQUEST
检查出来:
编辑:
如果您可以使用PHP,我建议您使用Snoopy PHP http://snoopy.sourceforge.net
它模拟Web浏览器,允许您进行进一步的机器人导航和html检索。它还模拟Cookies
EDIT2:
如果您不打算使用PHP,则需要使用CURL(在链接下方下载)。使用它,您将能够检索已发布登录页面的html。
http://curl.haxx.se/download.html
基本用法1: http://curl.haxx.se/docs/httpscripting.html
使用curl和POST的堆栈溢出帖子: login POST form with cURL
代码示例: http://www.yilmazhuseyin.com/blog/dev/curl-tutorial-examples-usage/
答案 1 :(得分:0)
我使用lynx和wget来解决这个问题。请阅读这篇文章中的最后一个答案。