0

我正在尝试编写一个与网页元素交互的 Powershell 脚本。为了学习脚本的概念,我使用 Armorgames.com 作为目标 url,我的目标是使用 powershell 登录该站点,然后根据指定的搜索条件搜索可用的游戏,然后将结果导出到 CSV . 随附的代码示例是我目前拥有的。但我无法理解我正在搜索的网页元素的哪些部分以及如何将值输入到可用字段中。我也收到错误“方法调用失败,因为 [mshtml.HTMLDocumentClass] 不包含名为 'getElementsById' 的方法”,我不明白为什么

$ie = New-Object -ComObject "InternetExplorer.Application"
$requestUrl = "https://armorgames.com/"
$userId = "username-input";
$passwordId = "password-input"
$signIn = "act"

$ie.visible = $true
#ie.silent = $true
$ie.navigate($requestUrl)
while ($ie.busy) {
    Start-Sleep -Milliseconds 100
}
$doc = $ie.Document
$doc.getElementsById("input") | % {
    if ($_.id -ne $null){
        if ($_.id.Contains($signIn)) { $btn = $_ }
        if ($_.id.Contains($passwordId)) { $pwd = $_ }
        if ($_.id.Contains($userId)) { $user = $_ }
    }
}

$user.value = "ExampleUser"
$pwd.value = "MyPassord"

$btn.disabled = $false
$btn.click()
Write-Output $ie
Write-Output "doc is $doc"
4

0 回答 0