繁体   English   中英

尝试向 Facebook 输入登录信息时,PowerShell 中出现“来自 HRESULT 的异常:0X800A01B6”错误

[英]'Exception from HRESULT: 0X800A01B6' error in PowerShell when trying to enter login information to Facebook

我用 PowerShell 编写了这段代码:

$username = "xxxxxx";
$password = "xxxxxx";
$url = "www.facebook.com/login";

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

($ie.document.getElementsByName("email") |select -first 1).value = $username;

当我收到此错误消息时:

Exception from HRESULT: 0x800A01B6
At line:1 char:1
+ ($ie.document.getElementsByName("email") |select -first 1).value = $u ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : OperationStopped: (:) [], NotSupportedException
+ FullyQualifiedErrorId : System.NotSupportedException

任何解决方案?

谢谢!

解决方法 始终使用以下方法而不是本机方法:

IHTMLDocument3_getElementsByTagName   
IHTMLDocument3_getElementsByName
IHTMLDocument3_getElementByID

感谢 Paul Lim 在这里

这可能发生在 IE 仍在加载页面或解析 DOM 时。 在访问页面元素之前尝试等待 IE 不忙。 对 IE 的Busy 属性进行简单检查即可。 像这样,

$username="myname"
$password="mypass"
$url = "www.facebook.com/login"
$ie = New-Object -com internetexplorer.application
$ie.visible = $true
$ie.navigate($url)

# Sleep while IE is busy. Check 10 times per second, adjust delay as needed
while($ie.Busy) { Start-Sleep -Milliseconds 100 }

# IE is not busy with document anymore, pass credentials and click the logon    
($ie.document.getElementsByName("email") |select -first 1).value = $username
($ie.document.getElementsByName("pass") |select -first 1).value = $password
($ie.document.getElementsByName("login") |select -first 1).click()

使用这个:

$Url = "http://websiteurl"
$ie = New-Object -com internetexplorer.application;
$ie.visible = $true; # make to $true to see the result in webpage
$ie.navigate($Url);
while ($ie.Busy -eq $true) { Start-Sleep -Seconds 10; }
($ie.Document.IHTMLDocument3_getElementsByName("btnname") | select -first 1).click();
$ie.quit()

根据我的经验,使用

do{Start-Sleep -Milliseconds 100}While($ie.Busy -eq $True)
do{Start-Sleep -Milliseconds 100}While($ie.ReadyState -ne 4)

仍然有机会从 HRESULT: 0x800A01B6 错误中得到异常!

但是如果你添加代码

do{
    Start-Sleep -Milliseconds 100
}While((($ie.document.getElementsByName("login")).GetType()) -eq "DBNull")

在您使用 $ie.document.getElementsByName 之前,错误代码 0x800A01B6 将不再发生

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM