首页 > 解决方案 > 如何制作有效的 power shell 脚本来填写网页上的表格?

问题描述

我正在尝试获取我找到的这个 powershell 代码,以登录到我的路由器登录页面,但 powershell 给我一个错误说

这是代码

    # 发现所有要使用的页面/表单和元素

    $url = 'http://192.168.8.1/#/login'
    ($FormElements = Invoke-WebRequest -Uri $url -SessionVariable fe)
    ($Form = $FormElements.Forms[0]) | 格式列表-强制
    $表格 | 获取会员
    $Form.Fields

    # 与网站页面交互

    $password = '我的密码'
    $loginUrl = 'http://192.168.8.1/#/login'

    $ie = New-Object -com internetexplorer.application
    $ie.visible = $true
    $ie.navigate($loginUrl)

    while ($ie.Busy -eq $true) { 开始睡眠 -Seconds 1 }

    ($ie.document.getElementById('gl-input loginInput') |
    选择 -first 1).value = $password
    开始-睡眠-秒 1

    $ie.Document.getElementsByName('new-password').Item().Click();
    开始-睡眠-秒 1

标签: formspowershellautocompleteelement

解决方案


你必须:

  1. 使用 Windows PowerShell,不使用 PowerShell (v7.0.x) 或 PowerShell Core (v6.xx)。
  2. 在使用此脚本之前初始化 Internet Explorer。
  3. 编写自己的脚本。这个脚本是......它有很多无用的代码,比如$Form | Get-Member. 看看这里

推荐阅读