forms - 如何制作有效的 power shell 脚本来填写网页上的表格?
问题描述
我正在尝试获取我找到的这个 powershell 代码,以登录到我的路由器登录页面,但 powershell 给我一个错误说
- $表格 | 获取会员
-
~~~~~~~~~~
- CategoryInfo : CloseError: (:) [Get-Member], InvalidOperationException
- FullyQualifiedErrorId : NoObjectInGetMember,Microsoft.PowerShell.Commands.GetMemberCommand
这是代码
# 发现所有要使用的页面/表单和元素 $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
解决方案
你必须:
- 使用 Windows PowerShell,不使用 PowerShell (v7.0.x) 或 PowerShell Core (v6.xx)。
- 在使用此脚本之前初始化 Internet Explorer。
- 编写自己的脚本。这个脚本是......它有很多无用的代码,比如
$Form | Get-Member
. 看看这里。
推荐阅读
- java - 是否可以通过 Azure 函数通过简单的 HTTP 请求查询 Azure VM?
- reactjs - NextJS:使用表格渲染 Markdown
- python - 如何在 django 中以一种形式过滤具有多个表单/多个选项的结果表?
- powershell - 使用 Powershell 创建团队、频道和创建文件
- php - 尝试在 null 上读取属性“up_title”(查看:C:\wamp64\www\resources\views\welcome.blade.php)
- amazon-web-services - 如何更改 AWS Amplify 中的第一个网页(母版页?)?
- file - tomcat:使用 Active Directory 身份验证从文件系统文件夹中导出静态内容(并且无需编写 Java .wars)
- diff - Mediawiki 中是否有可能在跨wiki 链接的wiki 上有不同页面的差异?
- scala - Scala - 无法解析符号 flatMap
- javascript - 如何在 React 中获取元素 onClick 的值并将其用作条件