2017-07-28 114 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