从终端登录网站表单
Website sign in form from terminal
我目前正在制作一个 bash 脚本,要求我登录网站,下载主页( 包括一些 HTML 表格),然后将表格导出到一份文件!
对我来说最困难的部分是处理网站登录。
我尝试使用 curl (curl --user user:pass domain) 但没有像我预期的那样工作。
如果您对如何使其工作或如何以不同的方式工作有任何想法,请告诉我。
提前致谢
网站源代码
<?xml version="1.0" encoding="utf-8" standalone="no" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta name="robots" content="noindex, nofollow" />
<meta name="Googlebot" content="noindex, nofollow" />
<meta http-equiv="Content-Language" content="en-gb" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>
Starbase
</title>
<script language="javascript" type="text/javascript">
//<![CDATA[
function showLoading() {
document.getElementById('lyrLoading').style.display = 'inline';
}
//]]>
</script>
</head>
<body link="#000080" vlink="#000080" alink="#000080">
<table border="0" width="100%" height="100%">
<tr>
<td>
<div align="center">
<p align="center">
<img border="0" src="images/imgLogoSmall.gif" />
</p>
<p align="center">
<font face="Arial" color="#FF0000" size="2">You need to enter both an e-mail address and password.</font>
</p>
<table border="0" width="250">
<tr>
<td>
<form onsubmit="javascript:window.setTimeout('showLoading();', 1);" method="post" action="/index.asp" name="loginform" id="loginform">
<input type="hidden" name="process" value="1" />
<p align="center">
<font face="Arial"><img border="0" src="images/imgUser.gif" /><br />
<input name="username" size="25" style="text-align: center; font-family: Arial; font-size: 14;" /></font>
</p>
<p align="center">
<font face="Arial"><img border="0" src="images/imgPassword.gif" /><br />
<input type="password" name="password" size="25" style="text-align: center; font-family: Arial; font-size: 14;" /></font>
</p>
<p align="center">
<font face="Arial"><input type="image" src="http://picpaste.com/extpics/btnLogIn-UM9GoIxr.gif" name="B1" /></font>
</p>
</form>
<table border="0" width="100%">
<tr>
<td align="center">
<a href="passwordMgmt.asp?action=1" rel="nofollow"><font face="Arial,helvetica" size="1">Forgot password</font></a>
</td>
<td align="center">
<p align="center">
<a href="passwordMgmt.asp?action=2" rel="nofollow"><font face="Arial,helvetica" size="1">Change password</font></a>
</p>
</td>
</tr>
</table>
</td>
</tr>
</table>
</div>
</td>
</tr>
</table>
<script type="text/javascript">
//<![CDATA[
document.loginform.username.focus();
//]]>
</script>
<div style="display: none; z-index: 5; position: absolute; width: 500px; height: 260px; top: 50%; left: 50%; margin-top: -130px; margin-left: -250px;" id="lyrLoading">
<div align="center">
<table border="0" width="100%" height="100%">
<tr>
<td>
<div align="center">
<table border="0" cellpadding="5" cellspacing="0" bgcolor="#FFFFFF" style="border: 2px solid #A6CDF9" width="200" height="130">
<tr>
<td>
<img border="0" src="images/imgLoading.gif" width="32" height="32" align="right" />
</td>
<td>
<p align="left">
<font face="arial,helvetica" size="2">Logging in...</font>
</p>
</td>
</tr>
</table>
</div>
</td>
</tr>
</table>
</div>
</div>
</body>
</html>
您似乎正在尝试使用基本身份验证凭据登录。
您的网页需要以下形式的表单数据:
curl --data "param1=value1¶m2=value2" http://example.com/
因此,在您的情况下,您应该提供类似于以下内容的内容:
curl --data "username=aUserName&password=thePassword" http://example.com/index.asp
资源:
https://superuser.com/questions/149329/what-is-the-curl-command-line-syntax-to-do-a-post-request
我目前正在制作一个 bash 脚本,要求我登录网站,下载主页( 包括一些 HTML 表格),然后将表格导出到一份文件!
对我来说最困难的部分是处理网站登录。
我尝试使用 curl (curl --user user:pass domain) 但没有像我预期的那样工作。
如果您对如何使其工作或如何以不同的方式工作有任何想法,请告诉我。
提前致谢
网站源代码
<?xml version="1.0" encoding="utf-8" standalone="no" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta name="robots" content="noindex, nofollow" />
<meta name="Googlebot" content="noindex, nofollow" />
<meta http-equiv="Content-Language" content="en-gb" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>
Starbase
</title>
<script language="javascript" type="text/javascript">
//<![CDATA[
function showLoading() {
document.getElementById('lyrLoading').style.display = 'inline';
}
//]]>
</script>
</head>
<body link="#000080" vlink="#000080" alink="#000080">
<table border="0" width="100%" height="100%">
<tr>
<td>
<div align="center">
<p align="center">
<img border="0" src="images/imgLogoSmall.gif" />
</p>
<p align="center">
<font face="Arial" color="#FF0000" size="2">You need to enter both an e-mail address and password.</font>
</p>
<table border="0" width="250">
<tr>
<td>
<form onsubmit="javascript:window.setTimeout('showLoading();', 1);" method="post" action="/index.asp" name="loginform" id="loginform">
<input type="hidden" name="process" value="1" />
<p align="center">
<font face="Arial"><img border="0" src="images/imgUser.gif" /><br />
<input name="username" size="25" style="text-align: center; font-family: Arial; font-size: 14;" /></font>
</p>
<p align="center">
<font face="Arial"><img border="0" src="images/imgPassword.gif" /><br />
<input type="password" name="password" size="25" style="text-align: center; font-family: Arial; font-size: 14;" /></font>
</p>
<p align="center">
<font face="Arial"><input type="image" src="http://picpaste.com/extpics/btnLogIn-UM9GoIxr.gif" name="B1" /></font>
</p>
</form>
<table border="0" width="100%">
<tr>
<td align="center">
<a href="passwordMgmt.asp?action=1" rel="nofollow"><font face="Arial,helvetica" size="1">Forgot password</font></a>
</td>
<td align="center">
<p align="center">
<a href="passwordMgmt.asp?action=2" rel="nofollow"><font face="Arial,helvetica" size="1">Change password</font></a>
</p>
</td>
</tr>
</table>
</td>
</tr>
</table>
</div>
</td>
</tr>
</table>
<script type="text/javascript">
//<![CDATA[
document.loginform.username.focus();
//]]>
</script>
<div style="display: none; z-index: 5; position: absolute; width: 500px; height: 260px; top: 50%; left: 50%; margin-top: -130px; margin-left: -250px;" id="lyrLoading">
<div align="center">
<table border="0" width="100%" height="100%">
<tr>
<td>
<div align="center">
<table border="0" cellpadding="5" cellspacing="0" bgcolor="#FFFFFF" style="border: 2px solid #A6CDF9" width="200" height="130">
<tr>
<td>
<img border="0" src="images/imgLoading.gif" width="32" height="32" align="right" />
</td>
<td>
<p align="left">
<font face="arial,helvetica" size="2">Logging in...</font>
</p>
</td>
</tr>
</table>
</div>
</td>
</tr>
</table>
</div>
</div>
</body>
</html>
您似乎正在尝试使用基本身份验证凭据登录。
您的网页需要以下形式的表单数据:
curl --data "param1=value1¶m2=value2" http://example.com/
因此,在您的情况下,您应该提供类似于以下内容的内容:
curl --data "username=aUserName&password=thePassword" http://example.com/index.asp
资源:
https://superuser.com/questions/149329/what-is-the-curl-command-line-syntax-to-do-a-post-request