2017-07-28 68 views
0

我想使用命令行工具来登录网站http://url/login.html 此页没有形式,但有三个输入字段调用-WebRequst登录网站

 <div class="login-form"> 
     <div class="phone-number"> 
      <input id="account" type="text" placeholder="Account" /> 
     </div> 
     <div class="code-input" style="position: relative;"> 
      <input id="acc_pass" type="password" placeholder="Password" style="height:35px;" /> 
     </div> 
     <p id="js_acc_error" style="color:red;margin-top:10px;"></p> 
     <div class="login-other"> 
      <input id="account_login_checkbox" type="checkbox" /> <span>Read and agree<a class="show-xieyi" style="color:#3a74ba;cursor:pointer;"> EUL </a></span> 
     </div> 
     <div style="display:none; margin:4px 0 0 0;"> 
     </div> 
     <div class="login-btn" style="margin:10px 0 0"> 
      <button id="account_login_btn" type="submit">Login</button> 
     </div> 
    </div> 

我用小提琴手捕获请求后,点击提交按钮和重放请求使用卷曲,但有时不起作用,因为cookie已更改。

所以我想使用命令填充输入字段,然后单击按钮来重放请求。如何填写字段并单击Powershell Invoke-WebRequest或其他命令行工具中的按钮?

谢谢。

+0

我发现如何填写字段$ WebResponse.InputFields.FindById('account')='username',但仍不知道如何提交此请求 –

+0

这里是头信息:Accept:application/json, text/javascript,*/*; Q = 0.01 siteApiManager:假 X-请求-随着:XMLHttpRequest的 的Referer:http://20.0.0.2/site3/e4db7920330c4b3f86700d35f080c5b6/login.html?_mp_cmp_ttime=1494465642965&weixin_tel_authed=false 接受语言:ZH-CN 接受 - 编码:gzip的,放气 的User-Agent:Mozilla的/ 5.0(Windows NT的10.0; WOW64;三叉戟/ 7.0; RV:11.0)等壁虎 主机:20.0.0.2 连接:保持活动 曲奇:maipu_uc_request_log_name = 39170; cmp_glb_param = 881f0923d82e3c3feb47aa5d69e7e337 –

回答

0

由于卷曲不能保存的cookies,所以我发现使用PowerShell调用IE浏览器和模拟手动输入

  1. 如果使用的Windows 10和IE 11,因为这个链接配置 https://blogs.msdn.microsoft.com/ieinternals/2011/08/03/default-integrity-level-and-automation/

  2. 取消复选框在兼容性视图设置

使用像这样的powershell

$url = "http://web.com/login.html" 
$username="username" 
$password="password" 
$ie = new-object -com "InternetExplorer.ApplicationMedium" 
$ie.visible=$false 
$ie.navigate("$url") 
while($ie.ReadyState -ne 4) {start-sleep -m 100} 
$ie.Document.IHTMLDocument3_getElementById("account").value = $username 
$ie.Document.IHTMLDocument3_getElementById("acc_pass").value = $password 
$ie.Document.IHTMLDocument3_getElementById("account_login_checkbox").checked=$true 
$ie.Document.IHTMLDocument3_getElementById("account_login_btn").click() 
start-sleep -m 1000 
$ie.Quit() 
[System.Runtime.Interopservices.Marshal]::ReleaseComObject($ie) 
Remove-Variable ie 
0

当您点击登录按钮,它很可能只是给一些HTTP请求该地址但POST方法。在PowerShell中你可以做这样的事情:

curl 'https://site/longin.html' -Body "account=john&acc_pass=1234&account_login_checkbox=false" -Method Post 

你可能需要调整这一点,但它应该工作。另外顺便说一下,curl只是powershell的Invoke-WebRequest的别名。

+0

我卷曲:405不允许的方法 –

+0

而且我用小提琴手捕获requets,像这样GET /cmp/InnerUserAuthController.do?method=auth&username=username&password=cmljaGllM%3D&tenantId=1&siteId=3&ajaxRequest=true HTTP/1.1 –

+0

那么这可能意味着你确实需要GET方法。尝试像这样''curl'/cmp/InnerUserAuthController.do?method=auth&username=usernam e&password = cmljaGllM%3D&tenantId = 1&siteI d = 3&ajaxRequest = true'-Method Get'。 – Jeysym