使用powershell i在网页中搜索字符串

使用powershell i在网页中搜索字符串,powershell,Powershell,我需要验证这个网站的用户名和密码。当我输入无效密码时,它应该检查页面中的字符串“invalid email”。应显示登录失败消息。但“成功”正在被展示。?错在哪里 $url = "https://www.jabong.com/customer/account/login/" $cred = Get-Credential #Read credentials $username = $cred.username $username = $username.Replace("\", "") $pas

我需要验证这个网站的用户名和密码。当我输入无效密码时,它应该检查页面中的字符串“invalid email”。应显示登录失败消息。但“成功”正在被展示。?错在哪里

$url = "https://www.jabong.com/customer/account/login/" 
$cred = Get-Credential #Read credentials
$username = $cred.username
$username = $username.Replace("\", "")
$password = $cred.GetNetworkCredential().password
$ie = New-Object -com internetexplorer.application; 
$ie.visible = $true; 
$ie.navigate($url); 
while ($ie.Busy -eq $true) 
{ 
Start-Sleep 1; 

} 
$ie.Document.getElementById("LoginForm_email").value = $username
$ie.Document.getElementByID("LoginForm_password").value=$password
$ie.Document.getElementByID("qa-login-button").Click();
while($ie.busy) {sleep 1}
$webClient = new-object System.Net.WebClient
$webClient.Headers.Add("user-agent", "PowerShell Script")
$output = $webClient.DownloadString("https://www.jabong.com/customer/account/login/")
if ($output -like "*Invalid mailid*") {
  "login failed"
} else {
  "success"
}
sleep(300)

虽然我大体上同意@Alexander Obersht,但你离成功只有一步之遥。通过创建$webClient=new object System.Net.webClient,您可以建立到网站的另一个会话,而实际上您应该在$ie对象内轮询当前会话。 试试这个:

$url=https://www.jabong.com/customer/account/login/ $cred=获取凭证读取凭证 $username=$cred.username $username=$username.Replace\, $password=$cred.GetNetworkCredential.password $ie=新对象-com internetexplorer.application; $ie.visible=$true; $ie.navigate$url; 而$ie.Busy-eq$true { 开始睡眠1; } $ie.Document.GetElementByIdLogInfo_email.value=$username $ie.Document.getElementByIDLoginForm_密码。值=$password $ie.Document.getElementByIDqa-login-button.Click; 而$ie.busy{sleep 1} $output=$ie.Document.Body.innerHTML 如果$output-如*无效邮件*{ 登录失败 }否则{ 成功 }
我还将您的匹配更改为无效邮件。

您的代码看起来像是找到并组合在一起的各种代码片段的混合体。虽然一般来说这是一种有效的方法,但它并不是这样工作的。您需要的是获取Fiddler或Wireshark,并分析web浏览器如何在此网站上进行身份验证。这可能是一个POST请求。然后,您可以使用WebClient或调用WebRequest(如果您有PS 3.0+来发送类似的请求)。老实说,这些都是相当基本的东西。