我想从Powershell开始我的旅程,但似乎我不知道为什么该网站上的按钮没有响应
(这是我的大学网站)
我希望能够通过脚本登录。
我一直在尝试
之类的其他变体 $submitButton = $ie.documentElement.getElementsByTagName("input") |
Where-Object {$_.value -eq ' Zaloguj się '}
$submitButton.click()
或
$submitButton = $ie.documentElement.getElementsByTagName("input") |
Where-Object {$_.type -eq 'submit'}
$submitButton.click()
但是我总是会出错。
您不能在空值表达式上调用方法
我想念什么?
答案 0 :(得分:1)
以这种方式尝试...
$ie = New-Object -com InternetExplorer.Application
$ie.visible=$true
$ie.navigate('https://s1.wcy.wat.edu.pl/ed')
while($ie.ReadyState -ne 4) {start-sleep -m 100}
$UserID = $ie.document.getElementsByTagName('INPUT') |
Where-Object {$($_.Name) -match 'userid'}
$UserId.value = 'UserID'
$UserPassword = $ie.document.getElementsByTagName('INPUT') |
Where-Object {$($_.Name) -match 'password'}
$UserPassword.value = 'password'
$Submit = $ie.document.getElementsByTagName('INPUT') |
Where-Object {$($_.Value) -match 'Zaloguj'}
$Submit.click()
由于采用了这种方式,因此INPUT更加可靠,因为它们都是INPUT标签。
$wcy = Invoke-WebRequest -Uri 'https://s1.wcy.wat.edu.pl/ed'
$wcy.Forms[0] | Format-List -Force
$wcy.Forms[0].Fields
$wcy.InputFields
我刚刚对此进行了测试,所以我知道它可以工作。好吧,它对我有用。好吧,当然是由于无效的凭据导致登录失败。 ;-}
由于未按预期读取字符串,因此未与-eq匹配(该错误消息)。使用匹配效果更好。