我们有这个网站,我想登录并执行一些自动化操作,以获取我想要的信息。
首先您需要将这些详细信息放在本网站的下方
http://ipamtool.*****.com/menandmice/Login.htm
Host:
Username:
Password:
然后一旦您成功登录,您将进入this site
我关注了 this site,这真的很有帮助,但是这个使用了表单,而我正在处理的网站没有,而是有这个 inputFields。所以我结束了这是我的代码:
$r = Invoke-WebRequest -Uri "http://ipamtool.*****.com/menandmice/Login.htm" -SessionVariable my_session
$form1 = $r.InputFields
$form1.FindById('itsServer').outerText = 'somehost'
$form1.FindById('itsUsername').outerText = 'somedomain\someuser'
$form1.FindById('itsPassword').outerText = 'somepassword'
$r = Invoke-WebRequest -Uri "http://ipamtool.*****.com/menandmice/Login.htm" -SessionVariable my_session
我的问题是我关注的网站使用 $form.Action
并且我尝试执行 .Action
方法,但它似乎在我的中不可用。
您如何使用 Invoke-WebRequest
登录页面并进入下一个页面?
我需要帮助。谢谢。
这是我的错误:
Invoke-WebRequest : Cannot convert 'Microsoft.PowerShell.Commands.WebCmdletElementCollection' to the type 'System.Uri'
required by parameter 'Uri'. Specified method is not supported.
At C:\Tools\ExtractDNS\ExtractDNS.ps1:27 char:24
+ Invoke-WebRequest -uri $form1 -WebSession $my_session
+ ~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Invoke-WebRequest], ParameterBindingException
+ FullyQualifiedErrorId : CannotConvertArgument,Microsoft.PowerShell.Commands.InvokeWebRequestCommand
答案 0 :(得分:0)
我认为发布的输出与上面的代码并不真正匹配。 -Uri
参数需要类似于 http://ipamtool.*****.com/menandmice/Login.htm
的内容,但可能不像错误所说的那样需要 $form1
。
请注意,您可以添加 -Method 'POST'
以向服务发送数据。有关详细信息,请参阅 documentation with Example 2。