首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用powershell i网页搜索字符串

使用powershell i网页搜索字符串
EN

Stack Overflow用户
提问于 2014-06-24 14:51:03
回答 1查看 1.1K关注 0票数 0

我需要验证这个网站的用户名和密码。当我输入无效密码时,它应该检查页面中字符串“无效电子邮件”。应该显示无法登录的消息。但是“成功”正在被展示出来。这是什么错误?

代码语言:javascript
复制
$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)
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-06-25 09:59:04

虽然我总体上同意亚历山大·奥伯希特的观点,但你离成功只有一步之遥。通过创建$webClient = new-object System.Net.WebClient,您可以为网站建立另一个会话,而实际上您应该在$ie对象中轮询当前会话。

试试这个:

代码语言:javascript
复制
$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}
$output = $ie.Document.Body.innerHTML
if ($output -like "*Invalid mail*") {
    "login failed"
} else {
    "success"
}

我还把你的对手改成了Invalid mail

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/24389753

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档