i,m编写一个powershell脚本以通过Internet Explorer打开网页,并检查网页以通过span标签在网页上找到链接,然后单击链接以打开链接,但是$ IE.Document.getElementsByTagName(“跨度”)| ? {$ _。InnerHTML -eq“ $ word”在Windows 7 powershell版本2中不起作用,脚本为:
while ( $row = sqlsrv_fetch_array($result_set) ) {
... do stuff ...
}
我想用Windows 7中的Powershell版本2替换任何使用此脚本的命令,但我不知道该命令可以做什么,找到我的想法链接,然后单击此脚本的链接!
答案 0 :(得分:0)
你好我的朋友@Theo
对此进行脚本更改:
$IE = new-object -com internetexplorer.application
$req = [System.Net.WebRequest]::Create("http://device.com/link.html")
$resp = $req.GetResponse()
$reqstream = $resp.GetResponseStream()
$stream = new-object System.IO.StreamReader $reqstream
$go = $stream.ReadToEnd()
$IE.navigate($go)
$IE.visible=$true
start-sleep 10
$req = [System.Net.WebRequest]::Create("http://device.com/word.html")
$resp = $req.GetResponse()
$reqstream = $resp.GetResponseStream()
$stream = new-object System.IO.StreamReader $reqstream
$word = $stream.ReadToEnd()
write-host $word
$Link = @($IE.Document.getElementsByTagName("span") | ? {$_.InnerHTML -eq "$word"})[0]
$Link.click()
不起作用,答案是:
Cannot find an overload for "getElementsByTagName" and the argument count: "1".
At line:16 char:44
+ $Link = @($IE.Document.getElementsByTagName <<<< ("span") | ? {$_.InnerHTML -eq "$word"})[0]
+ CategoryInfo : NotSpecified: (:) [], MethodException
+ FullyQualifiedErrorId : MethodCountCouldNotFindBest
You cannot call a method on a null-valued expression.
At line:17 char:12
+ $Link.click <<<< ()
+ CategoryInfo : InvalidOperation: (click:String) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull