gpt4 book ai didi

powershell - UseBasicParsing不返回HTML表单

转载 作者:行者123 更新时间:2023-12-03 01:10:40 24 4
gpt4 key购买 nike

我正在为网页创建表单登录监视器。这是代码:

$loginbase = '<input omitted>'
$loginURL = $loginbase + '<input omitted>'
$r = Invoke-WebRequest -Uri ($loginURL + 'logonform.jsp')
return $r;

$form = $r.Forms[0];

return $form

$form.Fields['aps'] = '<input omitted>';
$form.Fields['usr'] = '<input omitted>';
$form.Fields['pwd'] = '<input omitted>';

$r = Invoke-WebRequest -Uri ($loginURL + $form.Action) -Method POST -Body $form.Fields;

if ($r.Content -match 'setup()') {

if ($r.StatusCode -eq 200) {

Write-Host 'Message:' $r.StatusDescription;
Write-Host 'Statistic:' $r.StatusCode;
Exit 0;
}

Write-Host 'Message:' $r.StatusDescription;
Write-Host 'Statistic:' $r.StatusCode;
Exit 1;
}

Write-Host 'Message: Did not login';
Write-Host 'Statistic: 1';
Exit 1;

这在监视平台之外也可以正常工作,但是当我将此脚本放到平台中时,出现以下错误:
Invoke-WebRequest : The response content cannot be parsed because the Internet Explorer engine is not available, or Internet Explorer's first-launch configuration is not complete. Specify the UseBasicParsing parameter and try again. 
At line:3 char:6
+ $r = Invoke-WebRequest -Uri ($loginURL + 'logonform.jsp')
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotImplemented: (:) [Invoke-WebRequest], NotSupportedException
+ FullyQualifiedErrorId : WebCmdletIEDomNotSupportedException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand

Cannot index into a null array.
At line:5 char:1
+ $form = $r.Forms[0];
+ ~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : NullArray

Cannot index into a null array.
At line:7 char:1
+ $form.Fields['aps'] = '<input omitted>';
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : NullArray

Cannot index into a null array.
At line:8 char:1
+ $form.Fields['usr'] = '<input omitted>';
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : NullArray

Cannot index into a null array.
At line:9 char:1
+ $form.Fields['pwd'] = '<input omitted>';
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : NullArray

Invoke-WebRequest : The remote server returned an error: (404) Not Found.
At line:11 char:6
+ $r = Invoke-WebRequest -Uri ($loginURL + $form.Action) -Method POST -Body $form. ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest], WebException
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand

根据第一个错误的建议,我在初始Invoke-WebRequest语句中添加了“-UseBasicParsing”。当我在监视平台内部或外部运行脚本时,发生的事情是没有任何表单或输入字段从HTML提取。我得到以下内容:
StatusCode        : 200
StatusDescription : OK
Content : <!--
©2010 - 2013 SAP AG or an SAP affiliate company. All rights reserved.

SAP and other SAP products and services mentioned herein as well as their respective logos are trademarks or registered...
RawContent : HTTP/1.1 200 OK
Content-Length: 2561
Content-Type: text/html;charset=utf-8
Date: Tue, 11 Oct 2016 15:31:12 GMT
Expires: 0
Set-Cookie: JSESSIONID=DE3280200E764687D90E63E50A65452F; Path=/AdminTools...
Forms :
Headers : {[Content-Length, 2561], [Content-Type, text/html;charset=utf-8], [Date, Tue, 11 Oct 2016 15:31:12 GMT], [Expires, 0]...}
Images : {}
InputFields : {}
Links : {}
ParsedHtml :
RawContentLength : 2561

香港专业教育学院试图在谷歌和我们的监控平台的支持论坛上找到替代解决方案,但都没有超出如何使用Invoke-WebRequest的标准教程。

最佳答案

您尝试使用的功能(已解析为对象模型的HTML)需要Internet Explorer可用并进行初始化。 -UseBasicParsing专门针对您不需要的情况以及IE不可用的情况(例如在Server Core上)不进行这种解析。

如果您没有运行服务器核心,并且IE实际上可用,则可能是以下问题:

Internet Explorer's first-launch configuration is not complete.



在这种情况下,只需首次运行IE即可解决该问题。

如果脚本是作为服务帐户运行的,请确保使用该帐户登录一次并初始化IE(按用户)。

关于powershell - UseBasicParsing不返回HTML表单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39981427/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com